feat: add default storage dependencies and optimize imports
- Add nano-vectordb and networkx to pyproject.toml dependencies - Replace dynamic imports with direct imports for 4 default storage implementations - Improve startup performance while maintaining backward compatibility
This commit is contained in:
parent
51231c7647
commit
44b7ce222e
4 changed files with 25 additions and 14 deletions
|
|
@ -9,12 +9,8 @@ from lightrag.utils import (
|
|||
logger,
|
||||
compute_mdhash_id,
|
||||
)
|
||||
import pipmaster as pm
|
||||
|
||||
from lightrag.base import BaseVectorStorage
|
||||
|
||||
if not pm.is_installed("nano-vectordb"):
|
||||
pm.install("nano-vectordb")
|
||||
|
||||
from nano_vectordb import NanoVectorDB
|
||||
from .shared_storage import (
|
||||
get_storage_lock,
|
||||
|
|
|
|||
|
|
@ -6,12 +6,6 @@ from lightrag.types import KnowledgeGraph, KnowledgeGraphNode, KnowledgeGraphEdg
|
|||
from lightrag.utils import logger
|
||||
from lightrag.base import BaseGraphStorage
|
||||
from lightrag.constants import GRAPH_FIELD_SEP
|
||||
|
||||
import pipmaster as pm
|
||||
|
||||
if not pm.is_installed("networkx"):
|
||||
pm.install("networkx")
|
||||
|
||||
import networkx as nx
|
||||
from .shared_storage import (
|
||||
get_storage_lock,
|
||||
|
|
|
|||
|
|
@ -605,9 +605,28 @@ class LightRAG:
|
|||
)
|
||||
|
||||
def _get_storage_class(self, storage_name: str) -> Callable[..., Any]:
|
||||
import_path = STORAGES[storage_name]
|
||||
storage_class = lazy_external_import(import_path, storage_name)
|
||||
return storage_class
|
||||
# Direct imports for default storage implementations
|
||||
if storage_name == "JsonKVStorage":
|
||||
from lightrag.kg.json_kv_impl import JsonKVStorage
|
||||
|
||||
return JsonKVStorage
|
||||
elif storage_name == "NanoVectorDBStorage":
|
||||
from lightrag.kg.nano_vector_db_impl import NanoVectorDBStorage
|
||||
|
||||
return NanoVectorDBStorage
|
||||
elif storage_name == "NetworkXStorage":
|
||||
from lightrag.kg.networkx_impl import NetworkXStorage
|
||||
|
||||
return NetworkXStorage
|
||||
elif storage_name == "JsonDocStatusStorage":
|
||||
from lightrag.kg.json_doc_status_impl import JsonDocStatusStorage
|
||||
|
||||
return JsonDocStatusStorage
|
||||
else:
|
||||
# Fallback to dynamic import for other storage implementations
|
||||
import_path = STORAGES[storage_name]
|
||||
storage_class = lazy_external_import(import_path, storage_name)
|
||||
return storage_class
|
||||
|
||||
def insert(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ dependencies = [
|
|||
"configparser",
|
||||
"dotenv",
|
||||
"future",
|
||||
"nano-vectordb",
|
||||
"networkx",
|
||||
"numpy",
|
||||
"pandas>=2.0.0",
|
||||
"pipmaster",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue