Coverage for src/qdrant_loader_core/graph/__init__.py: 92%
25 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-20 10:12 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-20 10:12 +0000
1from __future__ import annotations
3import asyncio
4from typing import TYPE_CHECKING
6from .base import GraphEdge, GraphNode, GraphStore, SubGraph
7from .schema.utils import init_schema
9if TYPE_CHECKING:
10 from .falkor_store import FalkorGraphStore
12try:
13 from .falkor_store import FalkorGraphStore
14except ImportError:
15 FalkorGraphStore = None
18__all__ = [
19 "FalkorGraphStore",
20 "GraphNode",
21 "GraphEdge",
22 "GraphStore",
23 "SubGraph",
24]
27_graph_store: FalkorGraphStore | None = None
28_graph_store_lock = asyncio.Lock()
31async def get_graph_store(
32 host: str | None = None,
33 port: int | None = None,
34 password: str | None = None,
35 graph_name: str | None = None,
36 max_connections: int | None = None,
37) -> FalkorGraphStore:
38 global _graph_store
40 if FalkorGraphStore is None:
41 raise ModuleNotFoundError(
42 "FalkorGraphStore requires the 'graph' extra.\n"
43 "Install it with:\n"
44 " pip install qdrant-loader-core[graph]"
45 )
47 if _graph_store is None:
48 async with _graph_store_lock:
49 if _graph_store is None:
50 final_host = host or "localhost"
51 final_port = port if port is not None else 6379
52 final_graph = graph_name or "default_graph"
53 final_max_conn = max_connections if max_connections is not None else 10
55 _graph_store = FalkorGraphStore(
56 host=final_host,
57 port=int(final_port),
58 password=password,
59 graph_name=final_graph,
60 max_connections=final_max_conn,
61 )
63 await init_schema(_graph_store)
65 return _graph_store