lightrag-memgraph 0.1.0__py3-none-any.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.
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Optional
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from lightrag import LightRAG
|
|
6
|
+
from lightrag.kg.shared_storage import initialize_pipeline_status
|
|
7
|
+
from lightrag.llm.openai import gpt_4o_mini_complete, openai_embed
|
|
8
|
+
from lightrag.utils import setup_logger
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
+
MEMGRAPH_URI = os.getenv("MEMGRAPH_URI", "bolt://localhost:7687")
|
|
14
|
+
os.environ["MEMGRAPH_URI"] = MEMGRAPH_URI
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DummyEmbed:
|
|
18
|
+
def __init__(self, dim: int = 1):
|
|
19
|
+
self.embedding_dim = dim
|
|
20
|
+
|
|
21
|
+
async def __call__(self, texts: list[str]) -> np.ndarray:
|
|
22
|
+
return np.ones((len(texts), self.embedding_dim), dtype=float)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class MemgraphLightRAGWrapper:
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
log_level: str = "INFO",
|
|
29
|
+
disable_embeddings: bool = False,
|
|
30
|
+
):
|
|
31
|
+
self.log_level = log_level
|
|
32
|
+
self.disable_embeddings = disable_embeddings
|
|
33
|
+
self.rag: Optional[LightRAG] = None
|
|
34
|
+
|
|
35
|
+
# https://github.com/HKUDS/LightRAG/blob/main/lightrag/lightrag.py
|
|
36
|
+
# https://github.com/HKUDS/LightRAG/blob/main/lightrag/llm
|
|
37
|
+
async def initialize(self, **lightrag_kwargs) -> None:
|
|
38
|
+
setup_logger("lightrag", level=self.log_level)
|
|
39
|
+
logging.getLogger("nano-vectordb").setLevel(self.log_level)
|
|
40
|
+
logging.getLogger("pikepdf").setLevel(self.log_level)
|
|
41
|
+
if self.disable_embeddings:
|
|
42
|
+
lightrag_kwargs["embedding_func"] = DummyEmbed(dim=1)
|
|
43
|
+
lightrag_kwargs["vector_storage"] = "NanoVectorDBStorage"
|
|
44
|
+
if "working_dir" in lightrag_kwargs:
|
|
45
|
+
working_dir = lightrag_kwargs["working_dir"]
|
|
46
|
+
if not os.path.exists(working_dir):
|
|
47
|
+
os.mkdir(working_dir)
|
|
48
|
+
if "llm_model_func" not in lightrag_kwargs:
|
|
49
|
+
lightrag_kwargs["llm_model_func"] = gpt_4o_mini_complete
|
|
50
|
+
if "embedding_func" not in lightrag_kwargs:
|
|
51
|
+
lightrag_kwargs["embedding_func"] = openai_embed
|
|
52
|
+
if (
|
|
53
|
+
lightrag_kwargs["llm_model_func"] == gpt_4o_mini_complete
|
|
54
|
+
or lightrag_kwargs["embedding_func"] == openai_embed
|
|
55
|
+
):
|
|
56
|
+
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
|
57
|
+
if not openai_api_key:
|
|
58
|
+
raise EnvironmentError(
|
|
59
|
+
"OPENAI_API_KEY environment variable is not set. Please set your OpenAI API key."
|
|
60
|
+
)
|
|
61
|
+
self.rag = LightRAG(graph_storage="MemgraphStorage", **lightrag_kwargs)
|
|
62
|
+
await self.rag.initialize_storages()
|
|
63
|
+
await initialize_pipeline_status()
|
|
64
|
+
|
|
65
|
+
def get_lightrag(self) -> LightRAG:
|
|
66
|
+
if self.rag is None:
|
|
67
|
+
raise RuntimeError("LightRAG not initialized. Call initialize() first.")
|
|
68
|
+
return self.rag
|
|
69
|
+
|
|
70
|
+
# https://github.com/HKUDS/LightRAG/blob/main/lightrag/lightrag.py
|
|
71
|
+
async def ainsert(self, **kwargs) -> None:
|
|
72
|
+
"""
|
|
73
|
+
Example call: await lightrag_wrapper.ainsert(input=text, file_paths=[id])
|
|
74
|
+
|
|
75
|
+
If you want to inject info under each entity about the source input,
|
|
76
|
+
pass file_paths as a list of strings (ids don't work, not written under each entity).
|
|
77
|
+
"""
|
|
78
|
+
if self.rag is None:
|
|
79
|
+
raise RuntimeError("LightRAG not initialized. Call initialize() first.")
|
|
80
|
+
await self.rag.ainsert(**kwargs)
|
|
81
|
+
|
|
82
|
+
async def afinalize(self) -> None:
|
|
83
|
+
if self.rag is None:
|
|
84
|
+
raise RuntimeError("LightRAG not initialized. Call initialize() first.")
|
|
85
|
+
await self.rag.finalize_storages()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightrag-memgraph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LightRAG integration with Memgraph
|
|
5
|
+
Project-URL: Homepage, https://github.com/memgraph/ai-toolkit
|
|
6
|
+
Project-URL: Source, https://github.com/memgraph/ai-toolkit/tree/main/integrations/lightrag-memgraph
|
|
7
|
+
Project-URL: Issues, https://github.com/memgraph/ai-toolkit/issues
|
|
8
|
+
Author-email: Memgraph Tech Team <tech@memgraph.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: graph,integration,lightrag,memgraph,toolkit
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: lightrag-hku[api]==1.4.8.2
|
|
21
|
+
Requires-Dist: memgraph-toolbox>=0.1.6
|
|
22
|
+
Requires-Dist: numpy>=1.21.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: black>=22.0.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: isort>=5.0.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Why?
|
|
32
|
+
|
|
33
|
+
* High-quality, slow and high-cost entity extraction.
|
|
34
|
+
* Connect extracted entities with existing domain-specific entities.
|
|
35
|
+
* Cost for your scale (e.g., $ per your document page).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
lightrag_memgraph/__init__.py,sha256=-bcTvh8I881iZnvB55HX8JQ3VAbyvVvlsvRn6i8x4no,224
|
|
2
|
+
lightrag_memgraph/core.py,sha256=pu57AZAcFZptbUFhGMttrs7BlJMTKf0gT2J5vVjUdz4,3430
|
|
3
|
+
lightrag_memgraph-0.1.0.dist-info/METADATA,sha256=sbF8_i7Ja8uKBR_U8kvgrjFIna_WC1X1BPgeReX0q90,1437
|
|
4
|
+
lightrag_memgraph-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
+
lightrag_memgraph-0.1.0.dist-info/licenses/LICENSE,sha256=Zs4MZAXqusfO2KGQoAOuIqEUtojbyIYIkiJQ0BTt45o,1065
|
|
6
|
+
lightrag_memgraph-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Memgraph
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|