Skip to main content
Complete reference for all public classes and methods exported by graphrag_sdk.

Table of Contents


GraphRAG (Facade)

The main entry point. Three primary operations: ingest(), retrieve(), and completion().

Constructor

Public attributes: llm, embedder, schema, graph_store, vector_store

ingest()

Build a knowledge graph from one or more sources. Auto-detects loader from file extension. When a list of sources is provided, documents are ingested in parallel with bounded concurrency. Returns: IngestionResult for a single source, list[IngestionResult] for multiple sources.

retrieve()

Retrieve context from the knowledge graph without generating an answer. Use this to inspect retrieved context or pass it to your own LLM. Returns: RetrieverResult

completion()

Full RAG pipeline: retrieve context and generate an answer. When 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.
When history is provided, 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)

Deprecated. Use completion() for the full RAG pipeline or retrieve() for retrieval-only. Emits a DeprecationWarning and delegates to completion().

deduplicate_entities()

Post-ingestion entity deduplication. Groups entities by (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.
Call once after all documents are ingested. Returns: Number of duplicate entities merged.

finalize()

Run all post-ingestion steps after all documents are ingested. Bundles:
  1. deduplicate_entities() — global exact-name dedup
  2. backfill_entity_embeddings() — name-only embeddings
  3. embed_relationships() — fact text embeddings on RELATES edges
  4. ensure_indices() — all indexes
Returns: Dict with counts: entities_deduplicated, entities_embedded, relationships_embedded, indexes.

Sync Wrappers

Convenience methods that run the async versions in 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 extend DataModel (Pydantic BaseModel with extra="allow").

GraphNode

GraphRelationship

GraphData

TextChunk

TextChunks

DocumentInfo

DocumentOutput

IngestionResult

RagResult

RetrieverResult

RetrieverResultItem

ResolutionResult

ChatMessage

Validated message type for multi-turn conversations. Used by 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()

Deterministic entity ID from normalized name and optional type. When 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)

Built-in: TextLoader(encoding="utf-8"), PdfLoader()

ChunkingStrategy (ABC)

Built-in: FixedSizeChunking(chunk_size=1000, chunk_overlap=100)

ExtractionStrategy (ABC)

Built-in:
  • GraphExtraction(llm, *, entity_extractor=None, coref_resolver=None, entity_types=None, max_concurrency=None)
Entity Extractors (step 1 backends for GraphExtraction):
  • GLiNERExtractor(threshold=0.75, model_name="urchade/gliner_medium-v2.1") — default, local NER
  • LLMExtractor(llm, threshold=0.75) — LLM-based NER
  • Subclass EntityExtractor for custom backends

ResolutionStrategy (ABC)

Built-in:
  • ExactMatchResolution(resolve_property="id")
  • DescriptionMergeResolution(llm=None, force_summary_threshold=3, max_summary_tokens=500)

Ingestion Pipeline


Retrieval Strategies

RetrievalStrategy (ABC)

Uses the Template Method pattern.

LocalRetrieval

MultiPathRetrieval


Reranking Strategies

RerankingStrategy (ABC)

CosineReranker


Storage

GraphStore

VectorStore


Context

Execution context for logging and budget tracking.

Exceptions