gllm-datastore-binary 0.5.50__cp312-cp312-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gllm_datastore/__init__.pyi +0 -0
- gllm_datastore/cache/__init__.pyi +4 -0
- gllm_datastore/cache/base.pyi +84 -0
- gllm_datastore/cache/cache.pyi +137 -0
- gllm_datastore/cache/hybrid_cache/__init__.pyi +5 -0
- gllm_datastore/cache/hybrid_cache/file_system_hybrid_cache.pyi +50 -0
- gllm_datastore/cache/hybrid_cache/hybrid_cache.pyi +115 -0
- gllm_datastore/cache/hybrid_cache/in_memory_hybrid_cache.pyi +29 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/__init__.pyi +5 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/exact_key_matcher.pyi +44 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/fuzzy_key_matcher.pyi +70 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/key_matcher.pyi +60 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/semantic_key_matcher.pyi +93 -0
- gllm_datastore/cache/hybrid_cache/redis_hybrid_cache.pyi +34 -0
- gllm_datastore/cache/hybrid_cache/utils.pyi +36 -0
- gllm_datastore/cache/utils.pyi +34 -0
- gllm_datastore/cache/vector_cache/__init__.pyi +0 -0
- gllm_datastore/cache/vector_cache/eviction_manager/__init__.pyi +0 -0
- gllm_datastore/cache/vector_cache/eviction_manager/asyncio_eviction_manager.pyi +48 -0
- gllm_datastore/cache/vector_cache/eviction_manager/eviction_manager.pyi +38 -0
- gllm_datastore/cache/vector_cache/eviction_strategy/__init__.pyi +0 -0
- gllm_datastore/cache/vector_cache/eviction_strategy/eviction_strategy.pyi +34 -0
- gllm_datastore/cache/vector_cache/eviction_strategy/ttl_eviction_strategy.pyi +34 -0
- gllm_datastore/cache/vector_cache/vector_cache.pyi +99 -0
- gllm_datastore/constants.pyi +66 -0
- gllm_datastore/core/__init__.pyi +7 -0
- gllm_datastore/core/capabilities/__init__.pyi +7 -0
- gllm_datastore/core/capabilities/encryption_capability.pyi +21 -0
- gllm_datastore/core/capabilities/fulltext_capability.pyi +73 -0
- gllm_datastore/core/capabilities/graph_capability.pyi +70 -0
- gllm_datastore/core/capabilities/hybrid_capability.pyi +184 -0
- gllm_datastore/core/capabilities/vector_capability.pyi +90 -0
- gllm_datastore/core/filters/__init__.pyi +4 -0
- gllm_datastore/core/filters/filter.pyi +340 -0
- gllm_datastore/core/filters/schema.pyi +149 -0
- gllm_datastore/data_store/__init__.pyi +8 -0
- gllm_datastore/data_store/_elastic_core/__init__.pyi +0 -0
- gllm_datastore/data_store/_elastic_core/client_factory.pyi +66 -0
- gllm_datastore/data_store/_elastic_core/constants.pyi +27 -0
- gllm_datastore/data_store/_elastic_core/elastic_like_core.pyi +115 -0
- gllm_datastore/data_store/_elastic_core/index_manager.pyi +37 -0
- gllm_datastore/data_store/_elastic_core/query_translator.pyi +89 -0
- gllm_datastore/data_store/base.pyi +176 -0
- gllm_datastore/data_store/chroma/__init__.pyi +4 -0
- gllm_datastore/data_store/chroma/_chroma_import.pyi +13 -0
- gllm_datastore/data_store/chroma/data_store.pyi +201 -0
- gllm_datastore/data_store/chroma/fulltext.pyi +134 -0
- gllm_datastore/data_store/chroma/query.pyi +266 -0
- gllm_datastore/data_store/chroma/query_translator.pyi +41 -0
- gllm_datastore/data_store/chroma/vector.pyi +197 -0
- gllm_datastore/data_store/elasticsearch/__init__.pyi +5 -0
- gllm_datastore/data_store/elasticsearch/data_store.pyi +147 -0
- gllm_datastore/data_store/elasticsearch/fulltext.pyi +238 -0
- gllm_datastore/data_store/elasticsearch/query.pyi +118 -0
- gllm_datastore/data_store/elasticsearch/query_translator.pyi +18 -0
- gllm_datastore/data_store/elasticsearch/vector.pyi +180 -0
- gllm_datastore/data_store/exceptions.pyi +35 -0
- gllm_datastore/data_store/in_memory/__init__.pyi +5 -0
- gllm_datastore/data_store/in_memory/data_store.pyi +71 -0
- gllm_datastore/data_store/in_memory/fulltext.pyi +131 -0
- gllm_datastore/data_store/in_memory/query.pyi +175 -0
- gllm_datastore/data_store/in_memory/vector.pyi +174 -0
- gllm_datastore/data_store/opensearch/__init__.pyi +5 -0
- gllm_datastore/data_store/opensearch/data_store.pyi +160 -0
- gllm_datastore/data_store/opensearch/fulltext.pyi +240 -0
- gllm_datastore/data_store/opensearch/query.pyi +89 -0
- gllm_datastore/data_store/opensearch/query_translator.pyi +18 -0
- gllm_datastore/data_store/opensearch/vector.pyi +211 -0
- gllm_datastore/data_store/redis/__init__.pyi +5 -0
- gllm_datastore/data_store/redis/data_store.pyi +153 -0
- gllm_datastore/data_store/redis/fulltext.pyi +128 -0
- gllm_datastore/data_store/redis/query.pyi +428 -0
- gllm_datastore/data_store/redis/query_translator.pyi +37 -0
- gllm_datastore/data_store/redis/vector.pyi +131 -0
- gllm_datastore/data_store/sql/__init__.pyi +4 -0
- gllm_datastore/data_store/sql/constants.pyi +5 -0
- gllm_datastore/data_store/sql/data_store.pyi +201 -0
- gllm_datastore/data_store/sql/fulltext.pyi +164 -0
- gllm_datastore/data_store/sql/query.pyi +81 -0
- gllm_datastore/data_store/sql/query_translator.pyi +51 -0
- gllm_datastore/data_store/sql/schema.pyi +16 -0
- gllm_datastore/encryptor/__init__.pyi +4 -0
- gllm_datastore/encryptor/aes_gcm_encryptor.pyi +45 -0
- gllm_datastore/encryptor/capability/__init__.pyi +3 -0
- gllm_datastore/encryptor/capability/mixin.pyi +32 -0
- gllm_datastore/encryptor/encryptor.pyi +52 -0
- gllm_datastore/encryptor/key_ring/__init__.pyi +3 -0
- gllm_datastore/encryptor/key_ring/in_memory_key_ring.pyi +52 -0
- gllm_datastore/encryptor/key_ring/key_ring.pyi +45 -0
- gllm_datastore/encryptor/key_rotating_encryptor.pyi +60 -0
- gllm_datastore/graph_data_store/__init__.pyi +6 -0
- gllm_datastore/graph_data_store/graph_data_store.pyi +151 -0
- gllm_datastore/graph_data_store/graph_rag_data_store.pyi +29 -0
- gllm_datastore/graph_data_store/light_rag_data_store.pyi +93 -0
- gllm_datastore/graph_data_store/light_rag_postgres_data_store.pyi +96 -0
- gllm_datastore/graph_data_store/llama_index_graph_rag_data_store.pyi +49 -0
- gllm_datastore/graph_data_store/llama_index_neo4j_graph_rag_data_store.pyi +78 -0
- gllm_datastore/graph_data_store/mixins/__init__.pyi +3 -0
- gllm_datastore/graph_data_store/mixins/agentic_graph_tools_mixin.pyi +175 -0
- gllm_datastore/graph_data_store/nebula_graph_data_store.pyi +206 -0
- gllm_datastore/graph_data_store/neo4j_graph_data_store.pyi +182 -0
- gllm_datastore/graph_data_store/schema.pyi +27 -0
- gllm_datastore/graph_data_store/utils/__init__.pyi +6 -0
- gllm_datastore/graph_data_store/utils/constants.pyi +21 -0
- gllm_datastore/graph_data_store/utils/light_rag_em_invoker_adapter.pyi +56 -0
- gllm_datastore/graph_data_store/utils/light_rag_lm_invoker_adapter.pyi +43 -0
- gllm_datastore/graph_data_store/utils/llama_index_em_invoker_adapter.pyi +45 -0
- gllm_datastore/graph_data_store/utils/llama_index_lm_invoker_adapter.pyi +169 -0
- gllm_datastore/signature/__init__.pyi +0 -0
- gllm_datastore/signature/webhook_signature.pyi +31 -0
- gllm_datastore/sql_data_store/__init__.pyi +4 -0
- gllm_datastore/sql_data_store/adapter/__init__.pyi +0 -0
- gllm_datastore/sql_data_store/adapter/sqlalchemy_adapter.pyi +38 -0
- gllm_datastore/sql_data_store/constants.pyi +6 -0
- gllm_datastore/sql_data_store/sql_data_store.pyi +86 -0
- gllm_datastore/sql_data_store/sqlalchemy_sql_data_store.pyi +216 -0
- gllm_datastore/sql_data_store/types.pyi +31 -0
- gllm_datastore/utils/__init__.pyi +6 -0
- gllm_datastore/utils/converter.pyi +51 -0
- gllm_datastore/utils/dict.pyi +21 -0
- gllm_datastore/utils/ttl.pyi +25 -0
- gllm_datastore/utils/types.pyi +32 -0
- gllm_datastore/vector_data_store/__init__.pyi +6 -0
- gllm_datastore/vector_data_store/chroma_vector_data_store.pyi +259 -0
- gllm_datastore/vector_data_store/elasticsearch_vector_data_store.pyi +357 -0
- gllm_datastore/vector_data_store/in_memory_vector_data_store.pyi +179 -0
- gllm_datastore/vector_data_store/mixin/__init__.pyi +0 -0
- gllm_datastore/vector_data_store/mixin/cache_compatible_mixin.pyi +145 -0
- gllm_datastore/vector_data_store/redis_vector_data_store.pyi +191 -0
- gllm_datastore/vector_data_store/vector_data_store.pyi +146 -0
- gllm_datastore.build/.gitignore +1 -0
- gllm_datastore.cpython-312-darwin.so +0 -0
- gllm_datastore.pyi +178 -0
- gllm_datastore_binary-0.5.50.dist-info/METADATA +185 -0
- gllm_datastore_binary-0.5.50.dist-info/RECORD +137 -0
- gllm_datastore_binary-0.5.50.dist-info/WHEEL +5 -0
- gllm_datastore_binary-0.5.50.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from gllm_datastore.encryptor.encryptor import BaseEncryptor as BaseEncryptor
|
|
2
|
+
from gllm_datastore.encryptor.key_ring.key_ring import BaseKeyRing as BaseKeyRing
|
|
3
|
+
|
|
4
|
+
class InMemoryKeyRing(BaseKeyRing):
|
|
5
|
+
"""In-memory implementation of BaseKeyRing.
|
|
6
|
+
|
|
7
|
+
This class provides a simple in-memory storage for encryption keys and
|
|
8
|
+
their associated encryptors. All keys are stored in memory and will be
|
|
9
|
+
lost when the application terminates.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
encryptors (dict[str, BaseEncryptor]): A dictionary to store the keys and their associated encryptors.
|
|
13
|
+
"""
|
|
14
|
+
encryptors: dict[str, BaseEncryptor]
|
|
15
|
+
def __init__(self, encryptors: dict[str, BaseEncryptor] | None = None) -> None:
|
|
16
|
+
"""Initialize the InMemoryKeyRing.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
encryptors (dict[str, BaseEncryptor] | None, optional): A dictionary to store the keys and
|
|
20
|
+
their associated encryptors. Defaults to None.
|
|
21
|
+
"""
|
|
22
|
+
def get(self, key_id: str) -> BaseEncryptor:
|
|
23
|
+
"""Get an encryptor by key ID.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
key_id (str): ID of the key to retrieve.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
BaseEncryptor: The encryptor for the specified key.
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
KeyError: If key_id does not exist.
|
|
33
|
+
"""
|
|
34
|
+
def add(self, key_id: str, encryptor: BaseEncryptor) -> None:
|
|
35
|
+
"""Add a new key to the key ring.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
key_id (str): Unique identifier for the key.
|
|
39
|
+
encryptor (BaseEncryptor): The encryptor instance for this key.
|
|
40
|
+
|
|
41
|
+
Raises:
|
|
42
|
+
KeyError: If key_id already exists.
|
|
43
|
+
"""
|
|
44
|
+
def remove(self, key_id: str) -> None:
|
|
45
|
+
"""Remove a key from the key ring.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
key_id (str): ID of the key to remove.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
KeyError: If key_id does not exist.
|
|
52
|
+
"""
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from gllm_datastore.encryptor.encryptor import BaseEncryptor as BaseEncryptor
|
|
3
|
+
|
|
4
|
+
class BaseKeyRing(ABC):
|
|
5
|
+
"""Abstract base class defining the interface for managing multiple encryption keys."""
|
|
6
|
+
@abstractmethod
|
|
7
|
+
def get(self, key_id: str) -> BaseEncryptor:
|
|
8
|
+
"""Get an encryptor by key ID.
|
|
9
|
+
|
|
10
|
+
This method should be implemented by subclasses to provide the getting functionality.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
key_id (str): ID of the key to retrieve.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
BaseEncryptor: The encryptor for the specified key.
|
|
17
|
+
|
|
18
|
+
Raises:
|
|
19
|
+
NotImplementedError: If the method is not implemented by the subclass.
|
|
20
|
+
"""
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def add(self, key_id: str, encryptor: BaseEncryptor) -> None:
|
|
23
|
+
"""Add a new key to the key ring.
|
|
24
|
+
|
|
25
|
+
This method should be implemented by subclasses to provide the adding functionality.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
key_id (str): Unique identifier for the key.
|
|
29
|
+
encryptor (BaseEncryptor): The encryptor instance for this key.
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
NotImplementedError: If the method is not implemented by the subclass.
|
|
33
|
+
"""
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def remove(self, key_id: str) -> None:
|
|
36
|
+
"""Remove a key from the key ring.
|
|
37
|
+
|
|
38
|
+
This method should be implemented by subclasses to provide the removing functionality.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
key_id (str): ID of the key to remove.
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
NotImplementedError: If the method is not implemented by the subclass.
|
|
45
|
+
"""
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_datastore.encryptor.encryptor import BaseEncryptor as BaseEncryptor
|
|
3
|
+
from gllm_datastore.encryptor.key_ring.key_ring import BaseKeyRing as BaseKeyRing
|
|
4
|
+
|
|
5
|
+
class KeyRotatingEncryptor(BaseEncryptor):
|
|
6
|
+
"""Encryptor that supports key rotation through a key ring.
|
|
7
|
+
|
|
8
|
+
This encryptor uses a BaseKeyRing to manage multiple encryption keys.
|
|
9
|
+
Users must specify which key to use for encryption and decryption operations.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
key_ring (BaseKeyRing): The key ring managing encryption keys.
|
|
13
|
+
active_key_id (str): The ID of the current key to use for encryption.
|
|
14
|
+
"""
|
|
15
|
+
key_ring: Incomplete
|
|
16
|
+
def __init__(self, key_ring: BaseKeyRing, active_key_id: str) -> None:
|
|
17
|
+
"""Initialize KeyRotatingEncryptor with a key ring.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
key_ring (BaseKeyRing): The key ring to use for key management.
|
|
21
|
+
active_key_id (str): The ID of the current key to use for encryption.
|
|
22
|
+
"""
|
|
23
|
+
@property
|
|
24
|
+
def active_key_id(self) -> str:
|
|
25
|
+
"""Get the ID of the current key to use for encryption."""
|
|
26
|
+
@active_key_id.setter
|
|
27
|
+
def active_key_id(self, value: str) -> None:
|
|
28
|
+
"""Set the ID of the current key to use for encryption.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
value (str): The ID of the current key to use for encryption.
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
KeyError: If the specified key does not exist.
|
|
35
|
+
"""
|
|
36
|
+
def encrypt(self, plaintext: str) -> str:
|
|
37
|
+
"""Encrypt plaintext using the specified key.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
plaintext (str): The plaintext to encrypt.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
str: The encrypted data with key metadata, encoded in base64.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
KeyError: If the specified key does not exist.
|
|
47
|
+
"""
|
|
48
|
+
def decrypt(self, ciphertext: str) -> str:
|
|
49
|
+
"""Decrypt ciphertext the key detected from metadata.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
ciphertext (str): The encrypted data with key metadata.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
str: The decrypted plaintext.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the data format is invalid or decryption fails.
|
|
59
|
+
KeyError: If the required key is not available.
|
|
60
|
+
"""
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from gllm_datastore.graph_data_store.light_rag_postgres_data_store import LightRAGPostgresDataStore as LightRAGPostgresDataStore
|
|
2
|
+
from gllm_datastore.graph_data_store.llama_index_neo4j_graph_rag_data_store import LlamaIndexNeo4jGraphRAGDataStore as LlamaIndexNeo4jGraphRAGDataStore
|
|
3
|
+
from gllm_datastore.graph_data_store.nebula_graph_data_store import NebulaGraphDataStore as NebulaGraphDataStore
|
|
4
|
+
from gllm_datastore.graph_data_store.neo4j_graph_data_store import Neo4jGraphDataStore as Neo4jGraphDataStore
|
|
5
|
+
|
|
6
|
+
__all__ = ['LightRAGPostgresDataStore', 'LlamaIndexNeo4jGraphRAGDataStore', 'NebulaGraphDataStore', 'Neo4jGraphDataStore']
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
class BaseGraphDataStore(ABC):
|
|
5
|
+
"""Abstract base class for an async graph data store interface.
|
|
6
|
+
|
|
7
|
+
This class defines the asynchronous interface for all graph data store implementations.
|
|
8
|
+
It provides methods for creating, updating, and querying graph data.
|
|
9
|
+
"""
|
|
10
|
+
@abstractmethod
|
|
11
|
+
async def upsert_node(self, label: str, identifier_key: str, identifier_value: str, properties: dict[str, Any] | None) -> Any:
|
|
12
|
+
"""Upsert a node in the graph.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
label (str): The label of the node.
|
|
16
|
+
identifier_key (str): The key of the identifier.
|
|
17
|
+
identifier_value (str): The value of the identifier.
|
|
18
|
+
properties (dict[str, Any] | None, optional): The properties of the node. Defaults to None.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
Any: The result of the operation.
|
|
22
|
+
"""
|
|
23
|
+
@abstractmethod
|
|
24
|
+
async def upsert_relationship(self, node_source_key: str, node_source_value: str, relation: str, node_target_key: str, node_target_value: str, properties: dict[str, Any] | None) -> Any:
|
|
25
|
+
"""Upsert a relationship between two nodes in the graph.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
node_source_key (str): The key of the source node.
|
|
29
|
+
node_source_value (str): The value of the source node.
|
|
30
|
+
relation (str): The type of the relationship.
|
|
31
|
+
node_target_key (str): The key of the target node.
|
|
32
|
+
node_target_value (str): The value of the target node.
|
|
33
|
+
properties (dict[str, Any] | None, optional): The properties of the relationship. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Any: The result of the operation.
|
|
37
|
+
"""
|
|
38
|
+
@abstractmethod
|
|
39
|
+
async def delete_node(self, label: str, identifier_key: str, identifier_value: str) -> Any:
|
|
40
|
+
"""Delete a node from the graph.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
label (str): The label of the node.
|
|
44
|
+
identifier_key (str): The key of the identifier.
|
|
45
|
+
identifier_value (str): The identifier of the node.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Any: The result of the operation.
|
|
49
|
+
"""
|
|
50
|
+
@abstractmethod
|
|
51
|
+
async def delete_relationship(self, node_source_key: str, node_source_value: str, relation: str, node_target_key: str, node_target_value: str) -> Any:
|
|
52
|
+
"""Delete a relationship between two nodes in the graph.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
node_source_key (str): The key of the source node.
|
|
56
|
+
node_source_value (str): The identifier of the source node.
|
|
57
|
+
relation (str): The type of the relationship.
|
|
58
|
+
node_target_key (str): The key of the target node.
|
|
59
|
+
node_target_value (str): The identifier of the target node.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Any: The result of the operation.
|
|
63
|
+
"""
|
|
64
|
+
@abstractmethod
|
|
65
|
+
async def query(self, query: str, parameters: dict[str, Any] | None = None) -> list[dict[str, Any]]:
|
|
66
|
+
"""Query the graph data store.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
query (str): The query to be executed.
|
|
70
|
+
parameters (dict[str, Any] | None, optional): The parameters of the query. Defaults to None.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
list[dict[str, Any]]: The result of the query as a list of dictionaries.
|
|
74
|
+
"""
|
|
75
|
+
@abstractmethod
|
|
76
|
+
async def traverse_graph(self, node_properties: dict[str, Any], extracted_node_properties: list[str] | None = None, extracted_relationship_properties: list[str] | None = None, depth: int = 3) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
|
77
|
+
'''Traverse graph from a node with specified properties, ignoring relationship\'s direction, up to a given depth.
|
|
78
|
+
|
|
79
|
+
Example:
|
|
80
|
+
```python
|
|
81
|
+
nodes, relationships = await graph_data_store.traverse_graph(
|
|
82
|
+
node_properties={"name": "John Doe"},
|
|
83
|
+
extracted_node_properties=["name", "age"],
|
|
84
|
+
extracted_relationship_properties=["since"],
|
|
85
|
+
depth=1
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
Means starting from the node with property `name` equal to "John Doe", traverse
|
|
89
|
+
the graph up to depth 1, extracting the `name` and `age` properties from nodes
|
|
90
|
+
and the `since` property from relationships.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
nodes, relationships = await graph_data_store.traverse_graph(
|
|
94
|
+
node_properties={"name": "John Doe"},
|
|
95
|
+
depth=2
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
Means starting from the node with property `name` equal to "John Doe", traverse
|
|
99
|
+
the graph up to depth 2, extracting all properties from nodes and relationships.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
node_properties (dict[str, Any]): The properties of the starting node.
|
|
103
|
+
extracted_node_properties (list[str] | None, optional): The properties to extract from nodes during
|
|
104
|
+
traversal. If None or empty list, all node properties will be returned. Defaults to None.
|
|
105
|
+
extracted_relationship_properties (list[str] | None, optional): The properties to extract from relationships
|
|
106
|
+
during traversal. If None or empty list, all relationship properties will be returned. Defaults to None.
|
|
107
|
+
depth (int, optional): The depth of traversal. Defaults to 3.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
tuple[list[dict[str, Any]], list[dict[str, Any]]]: A tuple containing two lists:
|
|
111
|
+
- List of nodes with their extracted properties.
|
|
112
|
+
- List of relationships with their extracted properties.
|
|
113
|
+
|
|
114
|
+
Example return value:
|
|
115
|
+
nodes = [
|
|
116
|
+
{
|
|
117
|
+
"id": 1001,
|
|
118
|
+
"labels": ["Person"],
|
|
119
|
+
"properties": {
|
|
120
|
+
"name": "John Doe",
|
|
121
|
+
"age": 30,
|
|
122
|
+
"occupation": "Engineer"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": 2001,
|
|
127
|
+
"labels": ["Company"],
|
|
128
|
+
"properties": {
|
|
129
|
+
"name": "TechCorp",
|
|
130
|
+
"industry": "Technology",
|
|
131
|
+
"employees": 500
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
relationships = [
|
|
137
|
+
{
|
|
138
|
+
"id": 5002,
|
|
139
|
+
"type": "FRIEND_OF",
|
|
140
|
+
"start_node": 1001,
|
|
141
|
+
"end_node": 1002,
|
|
142
|
+
"properties": {
|
|
143
|
+
"since": "2018-05-20",
|
|
144
|
+
"closeness": 8
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
'''
|
|
149
|
+
@abstractmethod
|
|
150
|
+
async def close(self) -> None:
|
|
151
|
+
"""Close the graph data store."""
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
class BaseGraphRAGDataStore(ABC):
|
|
5
|
+
"""Abstract base class for graph RAG data stores in the retrieval system.
|
|
6
|
+
|
|
7
|
+
This class defines the interface for all graph-based Retrieval-Augmented
|
|
8
|
+
Generation (RAG) implementations. It provides methods for querying the graph with
|
|
9
|
+
natural language and managing document-related data.
|
|
10
|
+
"""
|
|
11
|
+
@abstractmethod
|
|
12
|
+
async def query(self, query: str, **kwargs: Any) -> list[dict[str, Any]]:
|
|
13
|
+
"""Query the graph RAG data store.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
query (str): The query to be executed.
|
|
17
|
+
**kwargs (Any): Additional keyword arguments.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
list[dict[str, Any]]: The result of the query as a list of dictionaries.
|
|
21
|
+
"""
|
|
22
|
+
@abstractmethod
|
|
23
|
+
async def delete_by_document_id(self, document_id: str, **kwargs: Any) -> None:
|
|
24
|
+
"""Delete nodes and edges by document ID.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
document_id (str): The document ID.
|
|
28
|
+
**kwargs (Any): Additional keyword arguments.
|
|
29
|
+
"""
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_core.schema import Chunk as Chunk
|
|
3
|
+
from gllm_datastore.graph_data_store.graph_rag_data_store import BaseGraphRAGDataStore as BaseGraphRAGDataStore
|
|
4
|
+
from gllm_datastore.graph_data_store.utils.constants import LightRAGConstants as LightRAGConstants, LightRAGKeys as LightRAGKeys
|
|
5
|
+
from gllm_datastore.graph_data_store.utils.light_rag_em_invoker_adapter import LightRAGEMInvokerAdapter as LightRAGEMInvokerAdapter
|
|
6
|
+
from lightrag import LightRAG
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
class BaseLightRAGDataStore(BaseGraphRAGDataStore):
|
|
10
|
+
"""LightRAG data store base class.
|
|
11
|
+
|
|
12
|
+
This class provides an abstract base class for the BaseGraphRAGDataStore interface
|
|
13
|
+
using LightRAG as the underlying technology. It handles indexing files
|
|
14
|
+
into a graph database, creating relationships between files and chunks,
|
|
15
|
+
and provides methods for deleting files and chunks from the graph.
|
|
16
|
+
|
|
17
|
+
Please use LightRAGPostgresDataStore or other concrete implementations instead.
|
|
18
|
+
|
|
19
|
+
To implement a concrete data store, inherit from this class and implement the
|
|
20
|
+
abstract methods.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
instance (LightRAG): The LightRAG instance to use.
|
|
24
|
+
is_initialized (bool): Whether the data store is initialized.
|
|
25
|
+
"""
|
|
26
|
+
instance: Incomplete
|
|
27
|
+
is_initialized: bool
|
|
28
|
+
def __init__(self, instance: LightRAG) -> None:
|
|
29
|
+
"""Initialize the LightRAG data store.
|
|
30
|
+
|
|
31
|
+
This is an abstract base class and cannot be instantiated directly.
|
|
32
|
+
Use LightRAGPostgresDataStore or other concrete implementations instead.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
instance (LightRAG): The LightRAG instance to use for indexing.
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
TypeError: If attempting to instantiate BaseLightRAGDataStore directly.
|
|
39
|
+
"""
|
|
40
|
+
async def ensure_initialized(self) -> None:
|
|
41
|
+
"""Ensure that the LightRAG data store is initialized.
|
|
42
|
+
|
|
43
|
+
This asynchronous method ensures that the LightRAG data store is initialized.
|
|
44
|
+
If the data store is not initialized, it will initialize it.
|
|
45
|
+
"""
|
|
46
|
+
async def map_file_id_to_chunk_ids_using_graph(self, file_id: str, chunk_ids: list[str]) -> None:
|
|
47
|
+
"""Create file and chunk nodes in the graph and establish relationships.
|
|
48
|
+
|
|
49
|
+
This asynchronous method creates a file node and multiple chunk nodes
|
|
50
|
+
in the graph database, then establishes relationships between the file
|
|
51
|
+
and its chunks. The relationships are necessary for retaining the relationships
|
|
52
|
+
between the file and its chunks when deleting the file.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
file_id (str): The ID of the file to create in the graph.
|
|
56
|
+
chunk_ids (list[str]): List of chunk IDs that belong to the file.
|
|
57
|
+
"""
|
|
58
|
+
async def insert(self, chunks: list[Chunk]) -> None:
|
|
59
|
+
"""Insert a chunk into the LightRAG data store.
|
|
60
|
+
|
|
61
|
+
This asynchronous method inserts a chunk into the LightRAG data store.
|
|
62
|
+
If the data store is not initialized, it will initialize it.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
chunks (list[Chunk]): The chunks to insert.
|
|
66
|
+
"""
|
|
67
|
+
async def query(self, query: str, **kwargs: Any) -> Any:
|
|
68
|
+
"""Query the LightRAG data store.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
query (str): The query to be executed.
|
|
72
|
+
**kwargs (Any): Additional keyword arguments.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Any: The result of the query.
|
|
76
|
+
"""
|
|
77
|
+
async def delete(self, chunk_id: str) -> None:
|
|
78
|
+
"""Delete a chunk from the LightRAG data store.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
chunk_id (str): The ID of the chunk to delete.
|
|
82
|
+
"""
|
|
83
|
+
async def delete_by_document_id(self, document_id: str, **kwargs: Any) -> None:
|
|
84
|
+
"""Delete a document/file and all its associated chunks from the LightRAG data store.
|
|
85
|
+
|
|
86
|
+
This asynchronous method retrieves all chunks associated with a document/file,
|
|
87
|
+
deletes each chunk from both the LightRAG system and the graph database,
|
|
88
|
+
and finally deletes the document/file node itself.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
document_id (str): The ID of the document to delete.
|
|
92
|
+
**kwargs (Any): Additional keyword arguments.
|
|
93
|
+
"""
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from contextlib import contextmanager
|
|
3
|
+
from gllm_datastore.graph_data_store.light_rag_data_store import BaseLightRAGDataStore as BaseLightRAGDataStore
|
|
4
|
+
from gllm_datastore.graph_data_store.utils.constants import LightRAGPostgresStorageConstants as LightRAGPostgresStorageConstants
|
|
5
|
+
from gllm_datastore.graph_data_store.utils.light_rag_em_invoker_adapter import LightRAGEMInvokerAdapter as LightRAGEMInvokerAdapter
|
|
6
|
+
from gllm_datastore.graph_data_store.utils.light_rag_lm_invoker_adapter import LightRAGLMInvokerAdapter as LightRAGLMInvokerAdapter
|
|
7
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker
|
|
8
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker
|
|
9
|
+
from lightrag import LightRAG
|
|
10
|
+
from pydantic import BaseModel
|
|
11
|
+
from typing import Any, Generator
|
|
12
|
+
|
|
13
|
+
class PostgresDBConfig(BaseModel):
|
|
14
|
+
"""Pydantic model containing PostgreSQL configuration parameters."""
|
|
15
|
+
host: str
|
|
16
|
+
port: int
|
|
17
|
+
user: str
|
|
18
|
+
password: str
|
|
19
|
+
database: str
|
|
20
|
+
workspace: str
|
|
21
|
+
|
|
22
|
+
@contextmanager
|
|
23
|
+
def postgres_config_context(config: PostgresDBConfig) -> Generator[None, None, None]:
|
|
24
|
+
"""Context manager to temporarily set postgres config.
|
|
25
|
+
|
|
26
|
+
This context manager is used to temporarily set the environment variables
|
|
27
|
+
for PostgreSQL configuration. It is used to set the environment variables
|
|
28
|
+
for the duration of the context manager's block as it is required by LightRAG.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
config (PostgresDBConfig): Pydantic model containing PostgreSQL configuration parameters.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Generator[None, None, None]: Generator object that can be used in a context manager.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
class LightRAGPostgresDataStore(BaseLightRAGDataStore):
|
|
38
|
+
'''Data store implementation for LightRAG-based graph RAG using PostgreSQL.
|
|
39
|
+
|
|
40
|
+
This class extends the LightRAGDataStore to use PostgreSQL as the graph database,
|
|
41
|
+
key-value store, and vector database.
|
|
42
|
+
|
|
43
|
+
To use this data store, please ensure that you have a PostgreSQL with AGE and PGVector extensions installed.
|
|
44
|
+
You can use the following docker run command to start a PostgreSQL container with AGE and PGVector extensions:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
docker run -p 5455:5432 -d --name postgres-LightRag shangor/postgres-for-rag:v1.0 sh -c "service postgresql start && sleep infinity"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Example:
|
|
51
|
+
```python
|
|
52
|
+
from gllm_inference.em_invoker import OpenAIEMInvoker
|
|
53
|
+
from gllm_inference.lm_invoker import OpenAILMInvoker
|
|
54
|
+
from gllm_datastore.graph_data_store.light_rag_postgres_data_store import LightRAGPostgresDataStore
|
|
55
|
+
|
|
56
|
+
# Create the indexer
|
|
57
|
+
data_store = await LightRAGPostgresDataStore(
|
|
58
|
+
lm_invoker=OpenAILMInvoker(model_name="gpt-4o-mini"),
|
|
59
|
+
em_invoker=OpenAIEMInvoker(model_name="text-embedding-3-small"),
|
|
60
|
+
postgres_db_user="rag",
|
|
61
|
+
postgres_db_password="rag",
|
|
62
|
+
postgres_db_name="rag",
|
|
63
|
+
postgres_db_host="localhost",
|
|
64
|
+
postgres_db_port=5455,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Retrieve using LightRAG instance
|
|
68
|
+
await data_store.query("What is AI?")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Attributes:
|
|
72
|
+
instance (LightRAG): The LightRAG instance used for indexing and querying.
|
|
73
|
+
lm_invoker_adapter (LightRAGLMInvokerAdapter): The adapter for the LM invoker.
|
|
74
|
+
em_invoker_adapter (LightRAGEMInvokerAdapter): The adapter for the EM invoker.
|
|
75
|
+
postgres_config (PostgresDBConfig): Pydantic model containing PostgreSQL configuration parameters.
|
|
76
|
+
'''
|
|
77
|
+
lm_invoker_adapter: Incomplete
|
|
78
|
+
em_invoker_adapter: Incomplete
|
|
79
|
+
postgres_config: Incomplete
|
|
80
|
+
def __init__(self, lm_invoker: BaseLMInvoker, em_invoker: BaseEMInvoker, postgres_db_host: str = 'localhost', postgres_db_port: int = 5432, postgres_db_user: str = 'postgres', postgres_db_password: str = 'password', postgres_db_name: str = 'postgres', postgres_db_workspace: str = 'default', use_cache: bool = False, lm_invoke_kwargs: dict[str, Any] | None = None, instance: LightRAG | None = None, **kwargs: Any) -> None:
|
|
81
|
+
'''Initialize the LightRAGPostgresIndexer.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
lm_invoker (BaseLMInvoker): The LM invoker to use.
|
|
85
|
+
em_invoker (BaseEMInvoker): The EM invoker to use.
|
|
86
|
+
postgres_db_host (str, optional): The host for the PostgreSQL database. Defaults to "localhost".
|
|
87
|
+
postgres_db_port (int, optional): The port for the PostgreSQL database. Defaults to 5432.
|
|
88
|
+
postgres_db_user (str, optional): The user for the PostgreSQL database. Defaults to "postgres".
|
|
89
|
+
postgres_db_password (str, optional): The password for the PostgreSQL database. Defaults to "password".
|
|
90
|
+
postgres_db_name (str, optional): The name for the PostgreSQL database. Defaults to "postgres".
|
|
91
|
+
postgres_db_workspace (str, optional): The workspace for the PostgreSQL database. Defaults to "default".
|
|
92
|
+
use_cache (bool, optional): Whether to enable caching for the LightRAG instance. Defaults to False.
|
|
93
|
+
lm_invoke_kwargs (dict[str, Any] | None, optional): Keyword arguments for the LM invoker. Defaults to None.
|
|
94
|
+
instance (LightRAG | None, optional): A configured LightRAG instance to use. Defaults to None.
|
|
95
|
+
**kwargs (Any): Additional keyword arguments.
|
|
96
|
+
'''
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from abc import ABC
|
|
3
|
+
from gllm_datastore.graph_data_store.graph_rag_data_store import BaseGraphRAGDataStore as BaseGraphRAGDataStore
|
|
4
|
+
from gllm_datastore.graph_data_store.utils import LlamaIndexEMInvokerAdapter as LlamaIndexEMInvokerAdapter, LlamaIndexLMInvokerAdapter as LlamaIndexLMInvokerAdapter
|
|
5
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker
|
|
6
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker
|
|
7
|
+
from llama_index.core.base.embeddings.base import BaseEmbedding
|
|
8
|
+
from llama_index.core.graph_stores.types import PropertyGraphStore
|
|
9
|
+
from llama_index.core.llms import LLM
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
class LlamaIndexGraphRAGDataStore(PropertyGraphStore, BaseGraphRAGDataStore, ABC):
|
|
13
|
+
"""Abstract base class for a LlamaIndex graph RAG data store.
|
|
14
|
+
|
|
15
|
+
This class provides a common interface for LlamaIndex-based graph RAG data stores.
|
|
16
|
+
It handles conversion from GLLM invokers to LlamaIndex LLM and embedding models.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
lm_invoker (BaseLMInvoker | None): The GLLM language model invoker.
|
|
20
|
+
em_invoker (BaseEMInvoker | None): The GLLM embedding model invoker.
|
|
21
|
+
llm (LLM | None): The LlamaIndex LLM instance (converted from lm_invoker if provided).
|
|
22
|
+
embed_model (BaseEmbedding | None): The LlamaIndex embedding instance (converted from em_invoker if provided).
|
|
23
|
+
"""
|
|
24
|
+
lm_invoker: Incomplete
|
|
25
|
+
em_invoker: Incomplete
|
|
26
|
+
llm: LLM | None
|
|
27
|
+
embed_model: BaseEmbedding | None
|
|
28
|
+
def __init__(self, lm_invoker: BaseLMInvoker | None = None, em_invoker: BaseEMInvoker | None = None, **kwargs: Any) -> None:
|
|
29
|
+
"""Initialize the LlamaIndexGraphRAGDataStore.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
lm_invoker (BaseLMInvoker | None, optional): GLLM language model invoker.
|
|
33
|
+
If provided, it will be automatically converted to a LlamaIndex LLM instance
|
|
34
|
+
using LlamaIndexLMInvokerAdapter. Defaults to None.
|
|
35
|
+
em_invoker (BaseEMInvoker | None, optional): GLLM embedding model invoker.
|
|
36
|
+
If provided, it will be automatically converted to a LlamaIndex BaseEmbedding instance
|
|
37
|
+
using LlamaIndexEMInvokerAdapter. Defaults to None.
|
|
38
|
+
**kwargs (Any): Additional keyword arguments passed to PropertyGraphStore.
|
|
39
|
+
"""
|
|
40
|
+
async def query(self, query: str, **kwargs: Any) -> Any:
|
|
41
|
+
"""Query the graph RAG data store.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
query (str): The query to be executed.
|
|
45
|
+
**kwargs (Any): Additional keyword arguments.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Any: The result of the query.
|
|
49
|
+
"""
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_datastore.graph_data_store.llama_index_graph_rag_data_store import LlamaIndexGraphRAGDataStore as LlamaIndexGraphRAGDataStore
|
|
3
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker
|
|
4
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker
|
|
5
|
+
from llama_index.graph_stores.neo4j import Neo4jPropertyGraphStore
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
class LlamaIndexNeo4jGraphRAGDataStore(LlamaIndexGraphRAGDataStore, Neo4jPropertyGraphStore):
|
|
9
|
+
'''Graph RAG data store for Neo4j.
|
|
10
|
+
|
|
11
|
+
This class extends the Neo4jPropertyGraphStore class from LlamaIndex.
|
|
12
|
+
This class provides an interface for graph-based Retrieval-Augmented Generation (RAG)
|
|
13
|
+
operations on Neo4j graph databases.
|
|
14
|
+
|
|
15
|
+
Attributes:
|
|
16
|
+
neo4j_version_tuple (tuple[int, ...]): The Neo4j version tuple.
|
|
17
|
+
lm_invoker (BaseLMInvoker | None): The GLLM language model invoker (inherited from parent).
|
|
18
|
+
em_invoker (BaseEMInvoker | None): The GLLM embedding model invoker (inherited from parent).
|
|
19
|
+
llm (LLM | None): The LlamaIndex LLM instance (converted from lm_invoker, inherited from parent).
|
|
20
|
+
embed_model (BaseEmbedding | None): The LlamaIndex embedding instance
|
|
21
|
+
(converted from em_invoker, inherited from parent).
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
```python
|
|
25
|
+
# Option 1: Use with GLLM invokers (recommended)
|
|
26
|
+
from gllm_inference.builder import build_lm_invoker, build_em_invoker
|
|
27
|
+
|
|
28
|
+
lm_invoker = build_lm_invoker(model_id="openai/gpt-4o-mini")
|
|
29
|
+
em_invoker = build_em_invoker(model_id="openai/text-embedding-3-small")
|
|
30
|
+
|
|
31
|
+
store = LlamaIndexNeo4jGraphRAGDataStore(
|
|
32
|
+
url="bolt://localhost:7687",
|
|
33
|
+
username="neo4j",
|
|
34
|
+
password="password",
|
|
35
|
+
lm_invoker=lm_invoker, # Optional: Auto-converted to LlamaIndex LLM
|
|
36
|
+
em_invoker=em_invoker, # Optional: Auto-converted to LlamaIndex Embedding
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Option 2: Use with LlamaIndex LLM/Embeddings directly
|
|
40
|
+
from llama_index.llms.openai import OpenAI
|
|
41
|
+
from llama_index.embeddings.openai import OpenAIEmbedding
|
|
42
|
+
|
|
43
|
+
store = LlamaIndexNeo4jGraphRAGDataStore(
|
|
44
|
+
url="bolt://localhost:7687",
|
|
45
|
+
username="neo4j",
|
|
46
|
+
password="password",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# Perform RAG query
|
|
50
|
+
results = await store.query("What is the relationship between X and Y?")
|
|
51
|
+
|
|
52
|
+
# Delete document data
|
|
53
|
+
await store.delete_by_document_id("doc123")
|
|
54
|
+
```
|
|
55
|
+
'''
|
|
56
|
+
neo4j_version_tuple: Incomplete
|
|
57
|
+
def __init__(self, url: str, username: str, password: str, lm_invoker: BaseLMInvoker | None = None, em_invoker: BaseEMInvoker | None = None, **kwargs: Any) -> None:
|
|
58
|
+
'''Initialize the LlamaIndexNeo4jGraphRAGDataStore.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
url (str): The Neo4j database URL (e.g., "bolt://localhost:7687").
|
|
62
|
+
username (str): The Neo4j database username.
|
|
63
|
+
password (str): The Neo4j database password.
|
|
64
|
+
lm_invoker (BaseLMInvoker | None, optional): GLLM language model invoker.
|
|
65
|
+
If provided, it will be automatically converted to a LlamaIndex LLM instance
|
|
66
|
+
by the parent class. Defaults to None.
|
|
67
|
+
em_invoker (BaseEMInvoker | None, optional): GLLM embedding model invoker.
|
|
68
|
+
If provided, it will be automatically converted to a LlamaIndex BaseEmbedding instance
|
|
69
|
+
by the parent class. Defaults to None.
|
|
70
|
+
**kwargs (Any): Additional keyword arguments passed to Neo4jPropertyGraphStore.
|
|
71
|
+
'''
|
|
72
|
+
async def delete_by_document_id(self, document_id: str, **kwargs: Any) -> None:
|
|
73
|
+
"""Delete nodes and edges by document ID.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
document_id (str): The document ID.
|
|
77
|
+
**kwargs (Any): Additional keyword arguments.
|
|
78
|
+
"""
|