FalkorGraphQueryEngine

class FalkorGraphQueryEngine()

This is a wrapper for FalkorDB KnowledgeGraph.

__init__

def __init__(name: str,
             host: str = "127.0.0.1",
             port: int = 6379,
             username: str | None = None,
             password: str | None = None,
             model: GenerativeModel = OpenAiGenerativeModel("gpt-4o"),
             ontology: Ontology | None = None)

Initialize a FalkorDB knowledge graph. Please also refer to https://github.com/FalkorDB/GraphRAG-SDK/blob/main/graphrag_sdk/kg.py

TODO: Fix LLM API cost calculation for FalkorDB useages.

Arguments:

  • name str - Knowledge graph name.
  • host str - FalkorDB hostname.
  • port int - FalkorDB port number.
  • username str|None - FalkorDB username.
  • password str|None - FalkorDB password.
  • model GenerativeModel - LLM model to use for FalkorDB to build and retrieve from the graph, default to use OAI gpt-4o.
  • ontology - FalkorDB knowledge graph schema/ontology, https://github.com/FalkorDB/GraphRAG-SDK/blob/main/graphrag_sdk/ontology.py If None, FalkorDB will auto generate an ontology from the input docs.

connect_db

def connect_db()

Connect to an existing knowledge graph.

init_db

def init_db(input_doc: list[Document])

Build the knowledge graph with input documents.

query

def query(question: str,
          n_results: int = 1,
          **kwargs) -> GraphStoreQueryResult

Query the knowledge graph with a question and optional message history.

Arguments:

  • question - a human input question.

  • n_results - number of returned results. kwargs:

  • messages - a list of message history.

  • Returns - FalkorGraphQueryResult

delete

def delete() -> bool

Delete graph and its data from database.