Commit ·
1e05ebd
1
Parent(s): 5d1f4ca
Fix Qdrant Cloud connection logic
Browse files- scripts/build_index.py +4 -1
- src/api/main.py +2 -0
- src/vectorstore/qdrant_store.py +17 -6
scripts/build_index.py
CHANGED
|
@@ -627,7 +627,10 @@ def main():
|
|
| 627 |
# Initialize Qdrant store
|
| 628 |
console.print("\n[bold cyan]Initializing Qdrant Store...[/bold cyan]")
|
| 629 |
try:
|
| 630 |
-
qdrant_manager = QdrantStoreManager(
|
|
|
|
|
|
|
|
|
|
| 631 |
qdrant_manager.initialize_collection(recreate=args.recreate_collection)
|
| 632 |
except Exception as e:
|
| 633 |
console.print(f"[bold red]Failed to initialize Qdrant: {e}[/bold red]")
|
|
|
|
| 627 |
# Initialize Qdrant store
|
| 628 |
console.print("\n[bold cyan]Initializing Qdrant Store...[/bold cyan]")
|
| 629 |
try:
|
| 630 |
+
qdrant_manager = QdrantStoreManager(
|
| 631 |
+
url=settings.qdrant_url,
|
| 632 |
+
api_key=settings.qdrant_api_key,
|
| 633 |
+
)
|
| 634 |
qdrant_manager.initialize_collection(recreate=args.recreate_collection)
|
| 635 |
except Exception as e:
|
| 636 |
console.print(f"[bold red]Failed to initialize Qdrant: {e}[/bold red]")
|
src/api/main.py
CHANGED
|
@@ -179,6 +179,8 @@ async def lifespan(app: FastAPI):
|
|
| 179 |
app_state.qdrant_manager = QdrantStoreManager(
|
| 180 |
collection_name=app_state.settings.qdrant_collection_name,
|
| 181 |
path=app_state.settings.qdrant_path,
|
|
|
|
|
|
|
| 182 |
embedding_dim=app_state.embedding_client.embedding_dim,
|
| 183 |
)
|
| 184 |
|
|
|
|
| 179 |
app_state.qdrant_manager = QdrantStoreManager(
|
| 180 |
collection_name=app_state.settings.qdrant_collection_name,
|
| 181 |
path=app_state.settings.qdrant_path,
|
| 182 |
+
url=app_state.settings.qdrant_url,
|
| 183 |
+
api_key=app_state.settings.qdrant_api_key,
|
| 184 |
embedding_dim=app_state.embedding_client.embedding_dim,
|
| 185 |
)
|
| 186 |
|
src/vectorstore/qdrant_store.py
CHANGED
|
@@ -97,7 +97,9 @@ class QdrantStoreManager:
|
|
| 97 |
self,
|
| 98 |
collection_name: Optional[str] = None,
|
| 99 |
path: Optional[str] = None,
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
batch_size: int = 100,
|
| 102 |
):
|
| 103 |
"""
|
|
@@ -106,21 +108,30 @@ class QdrantStoreManager:
|
|
| 106 |
Args:
|
| 107 |
collection_name: Name of the collection (default: from settings)
|
| 108 |
path: Path to Qdrant storage (default: from settings)
|
|
|
|
|
|
|
| 109 |
embedding_dim: Dimension of dense embeddings
|
| 110 |
batch_size: Batch size for bulk operations
|
| 111 |
"""
|
| 112 |
self.collection_name = collection_name or settings.qdrant_collection_name
|
| 113 |
self.path = Path(path or settings.qdrant_path)
|
|
|
|
|
|
|
| 114 |
self.embedding_dim = embedding_dim
|
| 115 |
self.batch_size = batch_size
|
| 116 |
|
| 117 |
-
# Create storage directory
|
| 118 |
-
self.
|
|
|
|
| 119 |
|
| 120 |
-
# Initialize Qdrant client
|
| 121 |
try:
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
except Exception as e:
|
| 125 |
logger.error(f"Failed to initialize Qdrant client: {e}")
|
| 126 |
raise
|
|
|
|
| 97 |
self,
|
| 98 |
collection_name: Optional[str] = None,
|
| 99 |
path: Optional[str] = None,
|
| 100 |
+
url: Optional[str] = None,
|
| 101 |
+
api_key: Optional[str] = None,
|
| 102 |
+
embedding_dim: int = 768, # Default for nomic-embed-text/all-mpnet
|
| 103 |
batch_size: int = 100,
|
| 104 |
):
|
| 105 |
"""
|
|
|
|
| 108 |
Args:
|
| 109 |
collection_name: Name of the collection (default: from settings)
|
| 110 |
path: Path to Qdrant storage (default: from settings)
|
| 111 |
+
url: Qdrant server URL (for remote Qdrant)
|
| 112 |
+
api_key: Qdrant API key (for Qdrant Cloud)
|
| 113 |
embedding_dim: Dimension of dense embeddings
|
| 114 |
batch_size: Batch size for bulk operations
|
| 115 |
"""
|
| 116 |
self.collection_name = collection_name or settings.qdrant_collection_name
|
| 117 |
self.path = Path(path or settings.qdrant_path)
|
| 118 |
+
self.url = url or settings.qdrant_url
|
| 119 |
+
self.api_key = api_key or settings.qdrant_api_key
|
| 120 |
self.embedding_dim = embedding_dim
|
| 121 |
self.batch_size = batch_size
|
| 122 |
|
| 123 |
+
# Create storage directory (only if local)
|
| 124 |
+
if not self.url:
|
| 125 |
+
self.path.mkdir(parents=True, exist_ok=True)
|
| 126 |
|
| 127 |
+
# Initialize Qdrant client
|
| 128 |
try:
|
| 129 |
+
if self.url:
|
| 130 |
+
self.client = QdrantClient(url=self.url, api_key=self.api_key)
|
| 131 |
+
logger.info(f"Initialized Qdrant client at {self.url} (remote)")
|
| 132 |
+
else:
|
| 133 |
+
self.client = QdrantClient(path=str(self.path))
|
| 134 |
+
logger.info(f"Initialized Qdrant client at {self.path} (local)")
|
| 135 |
except Exception as e:
|
| 136 |
logger.error(f"Failed to initialize Qdrant client: {e}")
|
| 137 |
raise
|