cleanup
Browse files- lightrag/kg/__init__.py +17 -18
- lightrag/lightrag.py +10 -6
lightrag/kg/__init__.py
CHANGED
@@ -135,24 +135,23 @@ STORAGES = {
|
|
135 |
"QdrantVectorDBStorage": ".kg.qdrant_impl",
|
136 |
}
|
137 |
|
138 |
-
def verify_storage_implementation(
|
139 |
-
storage_type: str, storage_name: str
|
140 |
-
) -> None:
|
141 |
-
"""Verify if storage implementation is compatible with specified storage type
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
storage_name: Storage implementation name
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
if storage_type not in STORAGE_IMPLEMENTATIONS:
|
151 |
-
raise ValueError(f"Unknown storage type: {storage_type}")
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
"QdrantVectorDBStorage": ".kg.qdrant_impl",
|
136 |
}
|
137 |
|
|
|
|
|
|
|
|
|
138 |
|
139 |
+
def verify_storage_implementation(storage_type: str, storage_name: str) -> None:
|
140 |
+
"""Verify if storage implementation is compatible with specified storage type
|
|
|
141 |
|
142 |
+
Args:
|
143 |
+
storage_type: Storage type (KV_STORAGE, GRAPH_STORAGE etc.)
|
144 |
+
storage_name: Storage implementation name
|
|
|
|
|
145 |
|
146 |
+
Raises:
|
147 |
+
ValueError: If storage implementation is incompatible or missing required methods
|
148 |
+
"""
|
149 |
+
if storage_type not in STORAGE_IMPLEMENTATIONS:
|
150 |
+
raise ValueError(f"Unknown storage type: {storage_type}")
|
151 |
+
|
152 |
+
storage_info = STORAGE_IMPLEMENTATIONS[storage_type]
|
153 |
+
if storage_name not in storage_info["implementations"]:
|
154 |
+
raise ValueError(
|
155 |
+
f"Storage implementation '{storage_name}' is not compatible with {storage_type}. "
|
156 |
+
f"Compatible implementations are: {', '.join(storage_info['implementations'])}"
|
157 |
+
)
|
lightrag/lightrag.py
CHANGED
@@ -8,7 +8,11 @@ from datetime import datetime
|
|
8 |
from functools import partial
|
9 |
from typing import Any, AsyncIterator, Callable, Iterator, cast, final
|
10 |
|
11 |
-
from lightrag.kg import
|
|
|
|
|
|
|
|
|
12 |
|
13 |
from .base import (
|
14 |
BaseGraphStorage,
|
@@ -251,6 +255,10 @@ class LightRAG:
|
|
251 |
The default function is :func:`.utils.convert_response_to_json`.
|
252 |
"""
|
253 |
|
|
|
|
|
|
|
|
|
254 |
_storages_status: StoragesStatus = field(default=StoragesStatus.NOT_CREATED)
|
255 |
|
256 |
def __post_init__(self):
|
@@ -278,11 +286,8 @@ class LightRAG:
|
|
278 |
# self.check_storage_env_vars(storage_name)
|
279 |
|
280 |
# Ensure vector_db_storage_cls_kwargs has required fields
|
281 |
-
default_vector_db_kwargs = {
|
282 |
-
"cosine_better_than_threshold": float(os.getenv("COSINE_THRESHOLD", "0.2"))
|
283 |
-
}
|
284 |
self.vector_db_storage_cls_kwargs = {
|
285 |
-
|
286 |
**self.vector_db_storage_cls_kwargs,
|
287 |
}
|
288 |
|
@@ -1463,7 +1468,6 @@ class LightRAG:
|
|
1463 |
|
1464 |
return result
|
1465 |
|
1466 |
-
|
1467 |
def check_storage_env_vars(self, storage_name: str) -> None:
|
1468 |
"""Check if all required environment variables for storage implementation exist
|
1469 |
|
|
|
8 |
from functools import partial
|
9 |
from typing import Any, AsyncIterator, Callable, Iterator, cast, final
|
10 |
|
11 |
+
from lightrag.kg import (
|
12 |
+
STORAGE_ENV_REQUIREMENTS,
|
13 |
+
STORAGES,
|
14 |
+
verify_storage_implementation,
|
15 |
+
)
|
16 |
|
17 |
from .base import (
|
18 |
BaseGraphStorage,
|
|
|
255 |
The default function is :func:`.utils.convert_response_to_json`.
|
256 |
"""
|
257 |
|
258 |
+
cosine_better_than_threshold: float = field(
|
259 |
+
default=float(os.getenv("COSINE_THRESHOLD", 0.2))
|
260 |
+
)
|
261 |
+
|
262 |
_storages_status: StoragesStatus = field(default=StoragesStatus.NOT_CREATED)
|
263 |
|
264 |
def __post_init__(self):
|
|
|
286 |
# self.check_storage_env_vars(storage_name)
|
287 |
|
288 |
# Ensure vector_db_storage_cls_kwargs has required fields
|
|
|
|
|
|
|
289 |
self.vector_db_storage_cls_kwargs = {
|
290 |
+
"cosine_better_than_threshold": self.cosine_better_than_threshold,
|
291 |
**self.vector_db_storage_cls_kwargs,
|
292 |
}
|
293 |
|
|
|
1468 |
|
1469 |
return result
|
1470 |
|
|
|
1471 |
def check_storage_env_vars(self, storage_name: str) -> None:
|
1472 |
"""Check if all required environment variables for storage implementation exist
|
1473 |
|