graphrag_sdk.
Table of Contents
- GraphRAG (Facade)
- Connection
- Providers
- Data Models
- Schema
- Ingestion Strategies
- Ingestion Pipeline
- Retrieval Strategies
- Reranking Strategies
- Storage
- Context
- Exceptions
GraphRAG (Facade)
The main entry point. Three primary operations:ingest(), retrieve(), and completion().
Constructor
Public attributes:
llm, embedder, schema, graph_store, vector_store
ingest()
Returns:
IngestionResult for a single source, list[IngestionResult] for multiple sources.
retrieve()
Returns:
RetrieverResult
completion()
history is provided, messages are passed natively to the LLM provider’s multi-turn chat API.
Returns:
RagResult
Conversation history:
History accepts a list of ChatMessage objects or plain dicts with role and content keys. Supported roles: "system", "user", "assistant". Invalid roles raise ValueError.
completion() builds a native messages list: [system_prompt, *history, user_question] and calls LLMInterface.ainvoke_messages(). Without history, it uses the single-turn ainvoke() path.
query() (deprecated)
completion() for the full RAG pipeline or retrieve() for retrieval-only. Emits a DeprecationWarning and delegates to completion().
deduplicate_entities()
(normalized name, label) to prevent cross-type merging (e.g. Person “Paris” and Location “Paris” stay separate).
- Phase 1 (always): Exact name match — keeps longest description, remaps RELATES and MENTIONED_IN edges, deletes duplicates.
- Phase 2 (optional,
fuzzy=True): Embedding-based — embeds entity names, finds near-duplicates by cosine similarity.
finalize()
deduplicate_entities()— global exact-name dedupbackfill_entity_embeddings()— name-only embeddingsembed_relationships()— fact text embeddings on RELATES edgesensure_indices()— all indexes
entities_deduplicated, entities_embedded, relationships_embedded, indexes.
Sync Wrappers
asyncio.run().
Connection
ConnectionConfig
FalkorDBConnection
Providers
LLMInterface (ABC)
ainvoke_messages() is used by completion() when conversation history is provided. The default implementation concatenates messages into a single prompt string and calls ainvoke(), so custom providers work without changes. LiteLLM and OpenRouterLLM override this with native multi-turn implementations.
Embedder (ABC)
LLMBatchItem
LiteLLM
LiteLLMEmbedder
OpenRouterLLM
OpenRouterEmbedder
Data Models
All models extendDataModel (Pydantic BaseModel with extra="allow").
GraphNode
GraphRelationship
GraphData
TextChunk
TextChunks
DocumentInfo
DocumentOutput
IngestionResult
RagResult
RetrieverResult
RetrieverResultItem
ResolutionResult
ChatMessage
completion(history=...) and LLMInterface.ainvoke_messages(). Invalid roles raise a validation error on construction.
LLMMessage is a backward-compatible alias for ChatMessage.
LLMResponse
SearchType
Extraction Models
compute_entity_id()
entity_type is provided, appends a __type suffix to prevent cross-type collisions (e.g. paris__person vs paris__location). Without entity_type, returns just the normalized name for backwards compatibility.
Schema
EntityType
RelationType
PropertyType
GraphSchema
Ingestion Strategies
LoaderStrategy (ABC)
TextLoader(encoding="utf-8"), PdfLoader()
ChunkingStrategy (ABC)
FixedSizeChunking(chunk_size=1000, chunk_overlap=100)
ExtractionStrategy (ABC)
GraphExtraction(llm, *, entity_extractor=None, coref_resolver=None, entity_types=None, max_concurrency=None)
GraphExtraction):
GLiNERExtractor(threshold=0.75, model_name="urchade/gliner_medium-v2.1")— default, local NERLLMExtractor(llm, threshold=0.75)— LLM-based NER- Subclass
EntityExtractorfor custom backends
ResolutionStrategy (ABC)
ExactMatchResolution(resolve_property="id")DescriptionMergeResolution(llm=None, force_summary_threshold=3, max_summary_tokens=500)