graphrag_sdk package
Subpackages
- graphrag_sdk.schema package
- Submodules
- graphrag_sdk.schema.auto_detect module
- graphrag_sdk.schema.decoder module
- graphrag_sdk.schema.encoder module
- graphrag_sdk.schema.entity module
- graphrag_sdk.schema.from_graph module
- graphrag_sdk.schema.functions_gen module
- graphrag_sdk.schema.relation module
- graphrag_sdk.schema.schema module
- graphrag_sdk.schema.to_graph module
- graphrag_sdk.schema.tools_gen module
- Module contents
Submodules
graphrag_sdk.kg module
- class graphrag_sdk.kg.KnowledgeGraph(name: str, host: str = '127.0.0.1', port: int = 6379, username: str | None = None, password: str | None = None, model: str = 'gpt-4-1106-preview', schema: Schema | None = None)[source]
Bases:
objectKnowledge Graph model data as a network of entities and relations To create one it is best to provide a schema which will define the graph’s ontology In addition to a set of sources from which entities and relations will be extracted.
- ask(question: str, history: list | None = None) tuple[str, list][source]
Query the knowledge graph using natural language if the query is asked as part of a longer conversation make sure to include past history.
- Returns:
tuple[str, list]: answer, conversation history
- Example:
>>> ans, history = kg.ask("Which actor has the most oscars") >>> ans, history = kg.ask("List a few movies in which that actored played in", history)
- delete() None[source]
Deletes the knowledge graph and any other related resource e.g. Schema, OpenAI assistant
- list_sources() list[AbstractSource][source]
List of sources associated with knowledge graph
- Returns:
list[AbstractSource]: sources
- property name
- process_sources(sources: list[AbstractSource]) None[source]
Add entities and relations found in sources into the knowledge-graph
- Parameters:
sources (list[AbstractSource]): list of sources to extract knowledge from
- property schame
- property schema
graphrag_sdk.prompts module
graphrag_sdk.query_graph module
graphrag_sdk.source module
- class graphrag_sdk.source.AbstractSource(path: str)[source]
Bases:
ABCAbstract class representing a source file
- class graphrag_sdk.source.HTML(path)[source]
Bases:
AbstractSourceHTML resource
- class graphrag_sdk.source.PDF(path)[source]
Bases:
AbstractSourcePDF resource
- graphrag_sdk.source.Source(path: str, instruction: str | None = None) AbstractSource[source]
Creates a source object
- Parameters:
path (str): path to source instruction (str): source specific instruction for the LLM
- Returns:
AbstractSource: source
- class graphrag_sdk.source.TEXT(path)[source]
Bases:
AbstractSourceTEXT resource