This commit is contained in:
Yannick Stephan
2025-02-20 13:44:17 +01:00
parent 4923f5c1d7
commit 8413537ad2
2 changed files with 27 additions and 24 deletions

View File

@@ -135,24 +135,23 @@ STORAGES = {
"QdrantVectorDBStorage": ".kg.qdrant_impl", "QdrantVectorDBStorage": ".kg.qdrant_impl",
} }
def verify_storage_implementation(
storage_type: str, storage_name: str
) -> None:
"""Verify if storage implementation is compatible with specified storage type
Args: def verify_storage_implementation(storage_type: str, storage_name: str) -> None:
storage_type: Storage type (KV_STORAGE, GRAPH_STORAGE etc.) """Verify if storage implementation is compatible with specified storage type
storage_name: Storage implementation name
Raises: Args:
ValueError: If storage implementation is incompatible or missing required methods storage_type: Storage type (KV_STORAGE, GRAPH_STORAGE etc.)
""" storage_name: Storage implementation name
if storage_type not in STORAGE_IMPLEMENTATIONS:
raise ValueError(f"Unknown storage type: {storage_type}")
storage_info = STORAGE_IMPLEMENTATIONS[storage_type] Raises:
if storage_name not in storage_info["implementations"]: ValueError: If storage implementation is incompatible or missing required methods
raise ValueError( """
f"Storage implementation '{storage_name}' is not compatible with {storage_type}. " if storage_type not in STORAGE_IMPLEMENTATIONS:
f"Compatible implementations are: {', '.join(storage_info['implementations'])}" raise ValueError(f"Unknown storage type: {storage_type}")
)
storage_info = STORAGE_IMPLEMENTATIONS[storage_type]
if storage_name not in storage_info["implementations"]:
raise ValueError(
f"Storage implementation '{storage_name}' is not compatible with {storage_type}. "
f"Compatible implementations are: {', '.join(storage_info['implementations'])}"
)

View File

@@ -8,7 +8,11 @@ from datetime import datetime
from functools import partial from functools import partial
from typing import Any, AsyncIterator, Callable, Iterator, cast, final from typing import Any, AsyncIterator, Callable, Iterator, cast, final
from lightrag.kg import STORAGE_ENV_REQUIREMENTS, STORAGES, verify_storage_implementation from lightrag.kg import (
STORAGE_ENV_REQUIREMENTS,
STORAGES,
verify_storage_implementation,
)
from .base import ( from .base import (
BaseGraphStorage, BaseGraphStorage,
@@ -251,6 +255,10 @@ class LightRAG:
The default function is :func:`.utils.convert_response_to_json`. The default function is :func:`.utils.convert_response_to_json`.
""" """
cosine_better_than_threshold: float = field(
default=float(os.getenv("COSINE_THRESHOLD", 0.2))
)
_storages_status: StoragesStatus = field(default=StoragesStatus.NOT_CREATED) _storages_status: StoragesStatus = field(default=StoragesStatus.NOT_CREATED)
def __post_init__(self): def __post_init__(self):
@@ -278,11 +286,8 @@ class LightRAG:
# self.check_storage_env_vars(storage_name) # self.check_storage_env_vars(storage_name)
# Ensure vector_db_storage_cls_kwargs has required fields # Ensure vector_db_storage_cls_kwargs has required fields
default_vector_db_kwargs = {
"cosine_better_than_threshold": float(os.getenv("COSINE_THRESHOLD", "0.2"))
}
self.vector_db_storage_cls_kwargs = { self.vector_db_storage_cls_kwargs = {
**default_vector_db_kwargs, "cosine_better_than_threshold": self.cosine_better_than_threshold,
**self.vector_db_storage_cls_kwargs, **self.vector_db_storage_cls_kwargs,
} }
@@ -1463,7 +1468,6 @@ class LightRAG:
return result return result
def check_storage_env_vars(self, storage_name: str) -> None: def check_storage_env_vars(self, storage_name: str) -> None:
"""Check if all required environment variables for storage implementation exist """Check if all required environment variables for storage implementation exist