org.llm4s.knowledgegraph.query

Members list

Type members

Classlikes

case class Citation(nodeId: String, nodeLabel: String, relationship: Option[String], property: String, value: String)

A citation tracking which graph element contributed to the answer.

A citation tracking which graph element contributed to the answer.

Value parameters

nodeId

The ID of the contributing node

nodeLabel

The label of the contributing node

property

The specific property that was cited

relationship

Optional relationship that connected this information

value

The cited value

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class GraphQAConfig(maxHops: Int, maxContextNodes: Int, maxContextEdges: Int, useRanking: Boolean, rankingAlgorithm: RankingAlgorithm, includeCitations: Boolean, temperature: Double)

Configuration for the graph-guided question answering pipeline.

Configuration for the graph-guided question answering pipeline.

Value parameters

includeCitations

Whether to track and return source citations

maxContextEdges

Maximum number of edges to include in LLM context

maxContextNodes

Maximum number of nodes to include in LLM context

maxHops

Maximum number of hops for graph traversal during context gathering

rankingAlgorithm

Which ranking algorithm to use (when useRanking is true)

temperature

LLM temperature for answer generation (lower = more deterministic)

useRanking

Whether to use graph ranking algorithms to prioritize entities

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
class GraphQAPipeline(llmClient: LLMClient, graphStore: GraphStore, config: GraphQAConfig)

Graph-guided question answering pipeline.

Graph-guided question answering pipeline.

Uses graph structure to provide rich context for LLM answers. The pipeline follows the pattern: identify entities -> traverse for context -> rank entities -> generate answer.

Multi-hop traversal follows relationship chains to gather evidence beyond direct neighbors. Citations track which nodes and edges contributed to the answer.

Value parameters

config

Pipeline configuration

graphStore

The graph store containing the knowledge graph

llmClient

The LLM client for entity identification and answer generation

Attributes

Supertypes
class Object
trait Matchable
class Any
case class GraphQAResult(answer: String, citations: Seq[Citation], entities: Seq[IdentifiedEntity], queryResult: GraphQueryResult)

Result of graph-guided question answering.

Result of graph-guided question answering.

Value parameters

answer

The generated answer text

citations

Sources that contributed to the answer

entities

Key entities identified in the question and used for context

queryResult

The raw graph query result used for context

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed trait GraphQuery

Algebraic data type representing structured graph query operations.

Algebraic data type representing structured graph query operations.

The LLM translates natural language questions into one of these query types, which are then executed against a org.llm4s.knowledgegraph.storage.GraphStore.

This approach is engine-agnostic — the same query ADT works with in-memory stores, JSON-backed stores, or future external graph database implementations.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object GraphQuery

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
GraphQuery.type
class GraphQueryExecutor(graphStore: GraphStore)

Executes GraphQuery operations against a GraphStore.

Executes GraphQuery operations against a GraphStore.

This component bridges the structured query ADT with the engine-agnostic storage layer, translating each query variant into the appropriate GraphStore and GraphEngine calls.

Value parameters

graphStore

The graph store to query against

Attributes

Supertypes
class Object
trait Matchable
class Any
case class GraphQueryResult(nodes: Seq[Node], edges: Seq[Edge], paths: Seq[List[Edge]], summary: String)

Result of executing a graph query.

Result of executing a graph query.

Value parameters

edges

The edges returned by the query (relationships between result nodes)

nodes

The nodes returned by the query

paths

Ordered paths found (for path queries)

summary

A human-readable summary of the result

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
class GraphQueryTranslator(llmClient: LLMClient, graphStore: GraphStore)

Translates natural language questions into structured GraphQuery operations using an LLM.

Translates natural language questions into structured GraphQuery operations using an LLM.

The translator provides the LLM with a summary of the graph's schema (node labels, relationship types, sample properties) so it can generate appropriate query operations.

Value parameters

graphStore

The graph store whose schema is used as context

llmClient

The LLM client to use for translation

Attributes

Supertypes
class Object
trait Matchable
class Any
object GraphRanking

Graph ranking algorithms for entity importance scoring.

Graph ranking algorithms for entity importance scoring.

Provides PageRank, betweenness centrality, closeness centrality, and degree centrality implementations that operate on the immutable Graph data structure.

These scores are used by GraphQAPipeline to prioritize which entities to include in LLM context when the result set exceeds context limits.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class IdentifiedEntity(mention: String, nodeId: String, nodeLabel: String, confidence: Double)

An entity identified from the user's question and matched to a graph node.

An entity identified from the user's question and matched to a graph node.

Value parameters

confidence

Matching confidence score (0.0 to 1.0)

mention

The text mention from the question

nodeId

The matched node ID in the graph

nodeLabel

The label of the matched node

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class NativeQuery(language: QueryLanguage, queryString: String, explanation: String)

A generated native query string for a specific graph query language.

A generated native query string for a specific graph query language.

Value parameters

explanation

Optional human-readable explanation of what the query does

language

The target query language

queryString

The generated query string

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
class NativeQueryGenerator(llmClient: LLMClient)

Generates native graph query strings (Cypher, Gremlin, SPARQL) from natural language or structured GraphQuery operations using an LLM.

Generates native graph query strings (Cypher, Gremlin, SPARQL) from natural language or structured GraphQuery operations using an LLM.

This is an extension point for graph databases that support native query languages. The primary query path uses GraphQueryExecutor against the GraphStore trait; this generator provides an alternative for engines where native queries are more efficient.

Value parameters

llmClient

The LLM client to use for query generation

Attributes

Supertypes
class Object
trait Matchable
class Any
sealed trait QueryLanguage

Supported native graph query languages.

Supported native graph query languages.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Cypher
object Gremlin
object SPARQL
object QueryLanguage

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait RankingAlgorithm

Available graph ranking algorithms for entity prioritization.

Available graph ranking algorithms for entity prioritization.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type