Graph
Package containing Graph Indexer modules.
Modules:
| Name | Description |
|---|---|
LlamaIndexGraphRAGIndexer |
A class for indexing elements using LlamaIndex. |
LightRAGGraphRAGIndexer |
A class for indexing elements using LightRAG. |
GraphIndexer |
A generic graph indexer for chunks already enriched with nodes/edges by IDRegulationGraphDataGenerator. |
GraphIndexer(graph_capability, index_name, use_namespaced_id=True)
Bases: BaseIndexer
Indexer that upserts pre-generated nodes/edges into a graph backend.
Consumes chunks whose metadata already contains nodes and edges lists
(produced by IDRegulationGraphDataGenerator, already deduplicated within
the document) and upserts them via any BaseGraphCapability implementation.
Every insert path deletes each incoming chunk's existing subgraph before upserting
its replacement, so re-indexing a chunk is idempotent: nodes/edges the new
version no longer produces are removed, while nodes a sibling chunk still
MENTIONS survive. Cross-call idempotency for untouched chunks is provided by
the backend's MERGE.
index_name acts as a namespace property stamped onto every node, allowing
multiple projects or pipelines to share one graph database without node ID
collisions. All delete operations are scoped to the same index_name.
Attributes:
| Name | Type | Description |
|---|---|---|
graph_capability |
BaseGraphCapability
|
The graph backend used for upserts. |
index_name |
str
|
Namespace property injected onto every node. |
use_namespaced_id |
bool
|
Whether chunk-retrieval lookups also match the namespaced chunk id. |
logger |
Logger
|
Logger instance for this indexer. |
_chunk_deleter |
BaseChunkSubgraphDeleter | None
|
Cached chunk deletion strategy resolved for the backend. |
_chunk_writer |
BaseChunkSubgraphWriter | None
|
Cached subgraph-write strategy resolved for the backend. |
_chunk_reader |
BaseChunkReader | None
|
Cached chunk retrieval strategy resolved for the backend. |
Initialize the indexer with a graph capability and a namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_capability
|
BaseGraphCapability
|
Graph capability obtained via a
datastore's |
required |
index_name
|
str
|
Namespace string stamped as a property on every node. Scopes all reads and deletes so multiple pipelines can share one database. |
required |
use_namespaced_id
|
bool
|
Whether chunk-retrieval lookups ( |
True
|
delete_chunk(chunk_id, file_id='', **kwargs)
Delete nodes and edges owned exclusively by the given chunk.
Uses the Chunk node's MENTIONS edges as the ownership manifest.
Content nodes referenced by other chunks are preserved; structural edges
carrying this chunk's chunk_id property are removed.
Note
Provenance re-homing (updating stale chunk_id/file_id properties
on surviving shared nodes) is deferred to a follow-up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The chunk identifier. |
required |
file_id
|
str
|
Accepted for interface compatibility. Defaults to "". |
''
|
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Result dict with |
delete_file_chunks(file_id, **kwargs)
Delete all nodes produced by a given file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The file identifier stored on nodes by |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Result dict with |
get_chunk(chunk_id, file_id, **kwargs)
Get a single chunk by chunk ID and file ID.
Returns None when the chunk's Chunk node has no retrievable payload —
either indexed before this feature shipped, or belonging to a document with no
regulation_id (the generator emits no Chunk node for those) — the same
as when the chunk simply does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
Chunk identifier. |
required |
file_id
|
str
|
File identifier. Accepted for interface compatibility; not
used for the lookup, since |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: The chunk data following the Element structure with |
get_file_chunks(file_id, page=0, size=20, **kwargs)
Get chunks for a specific file with pagination support.
Chunks whose Chunk node has no retrievable payload — either indexed before
this feature shipped, or belonging to a document with no regulation_id (the
generator emits no Chunk node for those) — are excluded, not surfaced as an
error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
File identifier. |
required |
page
|
int
|
Page number. Defaults to 0. |
0
|
size
|
int
|
Page size. Defaults to 20. |
20
|
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response containing: 1. chunks (list[dict[str, Any]]): List of chunks with text, structure, and metadata. 2. pagination (dict[str, Any]): Pagination metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
index_chunk(element, **kwargs)
Index nodes and edges from a single enriched chunk.
The chunk's existing subgraph is deleted before the insert (after validation, so a malformed chunk never tears down the stored one), dropping now-stale nodes/edges while nodes a sibling chunk still references survive. Deleting a not-yet-existing chunk is a no-op, so a new chunk is still inserted. The delete and insert are not atomic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
dict[str, Any]
|
Enriched chunk. |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Result dict with |
index_chunks(elements, **kwargs)
Index nodes and edges from a list of enriched chunks.
Each incoming chunk's existing subgraph is deleted before the insert, dropping now-stale nodes/edges while nodes a sibling chunk still references survive. The delete and insert are not atomic, and deleting a not-yet-existing chunk is a no-op, so new chunks are still inserted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[dict[str, Any]]
|
Enriched chunks. |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Same shape as |
index_file_chunks(elements, file_id, **kwargs)
Index all nodes and edges from enriched chunks belonging to a file.
Each incoming chunk's existing subgraph is deleted before its nodes/edges are upserted, making the insert idempotent (see module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[dict[str, Any]]
|
Enriched chunks. |
required |
file_id
|
str
|
Identifier of the source file. Used for logging only; this indexer does not store per-file mappings. |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Result dict with |
update_chunk(element, **kwargs)
Update a chunk by chunk ID, re-indexing its subgraph via delete-then-insert.
The chunk identified by metadata["chunk_id"] is updated by removing its current
subgraph and upserting the incoming chunk's nodes and edges in its place:
- The existing chunk's owned subgraph is deleted via
delete_chunk. Shared content nodes still referenced by other chunks survive the delete. - The incoming chunk's nodes and edges are upserted, re-establishing any shared nodes the chunk still references. (The delete from step 1 already covers the delete-then-insert every insert path performs, so this does not delete again.)
The incoming chunk is validated before the delete so a malformed update cannot tear down the existing subgraph without inserting a new one in its place.
Updating a chunk that does not exist fails with a "Chunk not found" error rather than
inserting it: delete-then-insert only replaces an existing chunk. This mirrors
VectorDBIndexer.update_chunk, whose own delete_chunk is likewise a graceful
no-op while its update_chunk rejects a missing chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
dict[str, Any]
|
Enriched chunk carrying |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Result dict with |
update_chunk_metadata(chunk_id, file_id, metadata, **kwargs)
Patch graph metadata for a chunk.
Honors the BaseIndexer patch contract: the graph persists nodes/edges
(decomposed into graph elements, plus chunk_id/file_id/index_name
stamped on each), and every other field via the retrievable
CHUNK_ELEMENT_JSON_KEY payload (see _augment_chunk_node).
- If
metadatacontainsnodesoredges: the chunk's subgraph is rebuilt viaupdate_chunk(delete-then-reinsert), which also refreshes the retrievable payload. The rebuilt payload carries over the chunk's currenttext/structure(read via the chunk reader beforehand, falling back toUNCATEGORIZED_TEXTfor a chunk with no existing retrievable payload) since this patch only touches graph metadata. This fails with a "Chunk not found" error when the chunk does not exist, mirroringupdate_chunk. Note thatupdate_chunkrequires bothnodesandedges, so a patch carrying only one surfaces that validation error. - Otherwise: the patch (excluding the
chunk_id/file_ididentity keys) is merged into the chunk's current retrievable metadata and re-serialized in place. Fails with "Chunk not found" if no chunk matches; a chunk that exists but has no retrievable payload (indexed before chunk retrieval shipped) fails with a distinct message directing the caller to re-index orupdate_chunkto upgrade it. This merge is not atomic with a concurrentupdate_chunk/index_chunkon the samechunk_id: a full subgraph replacement landing between the read and the write here can be silently overwritten, the same non-atomicity already documented for this class's delete-then-insert paths. If theChunknode no longer exists at write time, the write matches nothing and fails with "Chunk not found" rather than silently dropping the patch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to update. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
metadata
|
dict[str, Any]
|
The metadata fields to update. |
required |
**kwargs
|
Any
|
Unused; accepted for interface compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Result dict with |
LightRAGGraphRAGIndexer(graph_store)
Bases: BaseGraphRAGIndexer
Indexer abstract base class for LightRAG-based graph RAG.
How to run LightRAG with PostgreSQL using Docker:
docker run -p 5455:5432 -d --name postgres-LightRag shangor/postgres-for-rag:v1.0 sh -c "service postgresql start && sleep infinity"
Example
from gllm_inference.em_invoker import OpenAIEMInvoker
from gllm_inference.lm_invoker import OpenAILMInvoker
from gllm_docproc.indexer.graph.light_rag_graph_rag_indexer import LightRAGGraphRAGIndexer
from gllm_datastore.graph_data_store.light_rag_postgres_data_store import LightRAGPostgresDataStore
# Create the LightRAGPostgresDataStore instance
graph_store = LightRAGPostgresDataStore(
lm_invoker=OpenAILMInvoker(model_name="gpt-4o-mini"),
em_invoker=OpenAIEMInvoker(model_name="text-embedding-3-small"),
postgres_db_host="localhost",
postgres_db_port=5455,
postgres_db_user="rag",
postgres_db_password="rag",
postgres_db_name="rag",
postgres_db_workspace="default",
)
# Create the indexer
indexer = LightRAGGraphRAGIndexer(graph_store=graph_store)
# Create elements to index
elements = [
{
"text": "This is a sample document about AI.",
"structure": "uncategorized",
"metadata": {
"source": "sample.txt",
"source_type": "TEXT",
"loaded_datetime": "2025-07-10T12:00:00",
"chunk_id": "chunk_001",
"file_id": "file_001"
}
}
]
# Index the elements
indexer.index_file_chunks(elements, file_id="file_001")
Attributes:
| Name | Type | Description |
|---|---|---|
_graph_store |
BaseLightRAGDataStore
|
The LightRAG data store used for indexing and querying. |
Initialize the LightRAGGraphRAGIndexer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_store
|
BaseLightRAGDataStore
|
The LightRAG instance to use for indexing. |
required |
delete_chunk(chunk_id, file_id, **kwargs)
Delete a single chunk by chunk ID and file ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to delete. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status and error message. |
delete_file_chunks(file_id, **kwargs)
Delete all chunks for a specific file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The ID of the file whose chunks should be deleted. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status and error message. |
get_chunk(chunk_id, file_id, **kwargs)
Get a single chunk by chunk ID and file ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to retrieve. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: The chunk data, or None if not found. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
get_file_chunks(file_id, page=0, size=20, **kwargs)
Get chunks for a specific file with pagination support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The ID of the file to get chunks from. |
required |
page
|
int
|
The page number (0-indexed). Defaults to 0. |
0
|
size
|
int
|
The number of chunks per page. Defaults to 20. |
20
|
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with chunks list, total count, and pagination info. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
index_chunk(element, **kwargs)
Index a single chunk.
This method only indexes the chunk. It does NOT update the metadata of neighboring chunks (previous_chunk/next_chunk). The caller is responsible for maintaining chunk relationships by updating adjacent chunks' metadata separately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
dict[str, Any]
|
The chunk to be indexed. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status, error message, and chunk_id. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
index_chunks(elements, **kwargs)
Index multiple chunks.
This method enables indexing multiple chunks in a single operation without requiring file replacement semantics (i.e., it inserts or overwrites the provided chunks directly without first deleting existing chunks). The chunks provided can belong to multiple different files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[dict[str, Any]]
|
The chunks to be indexed. Each dict should follow the Element structure with 'text' and 'metadata' keys. Metadata must include 'file_id' and 'chunk_id'. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The response from the indexing process. Should include: 1. success (bool): True if indexing succeeded, False otherwise. 2. error_message (str): Error message if indexing failed, empty string otherwise. 3. total (int): The total number of chunks indexed. |
index_file_chunks(elements, file_id, **kwargs)
Index chunks for a specific file.
This method extracts text and chunk IDs from the provided elements, inserts them into the LightRAG system, and creates a graph structure connecting files to chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[dict[str, Any]]
|
The chunks to be indexed. |
required |
file_id
|
str
|
The ID of the file these chunks belong to. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status, error message, and total count. |
resolve_entities()
Resolve entities from the graph.
Currently, this method does nothing. Resolve entities has been implicitly implemented in the LightRAG instance.
update_chunk(element, **kwargs)
Update a chunk by chunk ID.
This method updates both the text content and metadata of a chunk. When text content is updated, the chunk should be re-processed through data generators and re-indexed with updated vector embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
dict[str, Any]
|
The updated chunk data. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status, error message, and chunk_id. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
update_chunk_metadata(chunk_id, file_id, metadata, **kwargs)
Update metadata for a specific chunk.
This method patches new metadata into the existing chunk metadata. Existing metadata fields will be overwritten, and new fields will be added. Identity metadata fields file_id and chunk_id should be preserved and not overwritten.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to update. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
metadata
|
dict[str, Any]
|
The metadata fields to update. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status and error message. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
LlamaIndexGraphRAGIndexer(graph_store, allowed_entity_types=None, allowed_relation_types=None, kg_validation_schema=None, strict_mode=False, kg_extractors=None, vector_store=None, max_triplets_per_chunk=10, num_workers=4, **kwargs)
Bases: BaseGraphRAGIndexer
Indexer for graph RAG using LlamaIndex.
Attributes:
| Name | Type | Description |
|---|---|---|
_index |
PropertyGraphIndex
|
Property graph index. |
_graph_store |
LlamaIndexGraphRAGDataStore
|
Storage for property graph. |
_strict_mode |
bool
|
Whether strict schema validation is enabled. |
Initialize the LlamaIndexGraphRAGIndexer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_store
|
LlamaIndexGraphRAGDataStore
|
Storage for property graph. The LLM and embedding model used for extraction are sourced from graph_store.llm and graph_store.embed_model. |
required |
allowed_entity_types
|
list[str] | None
|
List of allowed entity types. When strict_mode=True, only these types are extracted. When strict_mode=False, serves as hints. Defaults to None. |
None
|
allowed_relation_types
|
list[str] | None
|
List of allowed relationship types. Behavior depends on strict_mode. Defaults to None. |
None
|
kg_validation_schema
|
dict[str, list[str]] | None
|
Validation schema for strict mode. Maps entity types to their allowed outgoing relationship types. Format: {"ENTITY_TYPE": ["ALLOWED_REL1", "ALLOWED_REL2"], ...} Example: {"PERSON": ["WORKS_AT", "FOUNDED"], "ORGANIZATION": ["LOCATED_IN"]} Defaults to None. |
None
|
strict_mode
|
bool
|
If True, uses SchemaLLMPathExtractor with strict validation. If False (default), uses DynamicLLMPathExtractor with optional guidance. Defaults to False. |
False
|
kg_extractors
|
list[TransformComponent] | None
|
Custom list of extractors. If provided, overrides automatic extractor selection based on strict_mode. Defaults to None. |
None
|
vector_store
|
BasePydanticVectorStore | None
|
Storage for vector data. Defaults to None. |
None
|
max_triplets_per_chunk
|
int
|
Maximum triplets to extract per chunk. Defaults to 10. |
10
|
num_workers
|
int
|
Number of parallel workers. Defaults to 4. |
4
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
delete_chunk(chunk_id, file_id, **kwargs)
Delete a single chunk by chunk ID and file ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to delete. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status and error message. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
delete_file_chunks(file_id, **kwargs)
Delete all chunks for a specific file.
This method deletes all chunks from the knowledge graph based on the provided file_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The ID of the file whose chunks should be deleted. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status and error message. |
get_chunk(chunk_id, file_id, **kwargs)
Get a single chunk by chunk ID and file ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to retrieve. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: The chunk data, or None if not found. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
get_file_chunks(file_id, page=0, size=20, **kwargs)
Get chunks for a specific file with pagination support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The ID of the file to get chunks from. |
required |
page
|
int
|
The page number (0-indexed). Defaults to 0. |
0
|
size
|
int
|
The number of chunks per page. Defaults to 20. |
20
|
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with chunks list, total count, and pagination info. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
index_chunk(element, **kwargs)
Index a single chunk.
This method only indexes the chunk. It does NOT update the metadata of neighboring chunks (previous_chunk/next_chunk). The caller is responsible for maintaining chunk relationships by updating adjacent chunks' metadata separately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
dict[str, Any]
|
The chunk to be indexed. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status, error message, and chunk_id. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
index_chunks(elements, **kwargs)
Index multiple chunks.
This method enables indexing multiple chunks in a single operation without requiring file replacement semantics (i.e., it inserts or overwrites the provided chunks directly without first deleting existing chunks). The chunks provided can belong to multiple different files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[dict[str, Any]]
|
The chunks to be indexed. Each dict should follow the Element structure with 'text' and 'metadata' keys. Metadata must include 'file_id' and 'chunk_id'. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The response from the indexing process. Should include: 1. success (bool): True if indexing succeeded, False otherwise. 2. error_message (str): Error message if indexing failed, empty string otherwise. 3. total (int): The total number of chunks indexed. |
index_file_chunks(elements, file_id, **kwargs)
Index chunks for a specific file.
This method indexes chunks for a file.
Notes: - Currently only Neo4jPropertyGraphStore that is supported for indexing the metadata from the TextNode. - The 'chunk_id' parameter is used to specify the chunk ID for the elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[dict[str, Any]]
|
The chunks to be indexed. |
required |
file_id
|
str
|
The ID of the file these chunks belong to. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status, error message, and total count. |
resolve_entities()
Resolve entities in the graph.
Currently, this method does nothing.
update_chunk(element, **kwargs)
Update a chunk by chunk ID.
This method updates both the text content and metadata of a chunk. When text content is updated, the chunk should be re-processed through data generators and re-indexed with updated vector embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
dict[str, Any]
|
The updated chunk data. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status, error message, and chunk_id. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |
update_chunk_metadata(chunk_id, file_id, metadata, **kwargs)
Update metadata for a specific chunk.
This method patches new metadata into the existing chunk metadata. Existing metadata fields will be overwritten, and new fields will be added. Identity metadata fields file_id and chunk_id should be preserved and not overwritten.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
The ID of the chunk to update. |
required |
file_id
|
str
|
The ID of the file the chunk belongs to. |
required |
metadata
|
dict[str, Any]
|
The metadata fields to update. |
required |
**kwargs
|
Any
|
Additional keyword arguments for customization. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Response with success status and error message. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented. |