graphrag_sdk package

Subpackages

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: object

Knowledge 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.query_graph.query(kg, question: str, messages: list, model='gpt-4-1106-preview') str[source]
graphrag_sdk.query_graph.run_conversation(g, question, messages, model) str[source]
graphrag_sdk.query_graph.run_cypher_query(g, q)[source]

graphrag_sdk.source module

class graphrag_sdk.source.AbstractSource(path: str)[source]

Bases: ABC

Abstract class representing a source file

load() Iterator[Document][source]
class graphrag_sdk.source.HTML(path)[source]

Bases: AbstractSource

HTML resource

class graphrag_sdk.source.PDF(path)[source]

Bases: AbstractSource

PDF 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: AbstractSource

TEXT resource

graphrag_sdk.template module

Module contents