|
155 | 155 | " self.connected = True\n", |
156 | 156 | " print(f\"✅ Connected to in-memory vector store: {self.index_name}\")\n", |
157 | 157 | "\n", |
158 | | - " def load_documents(\n", |
159 | | - " self, documents: list[VectorStoreDocument], overwrite: bool = True\n", |
160 | | - " ) -> None:\n", |
| 158 | + " def create_index(self) -> None:\n", |
| 159 | + " \"\"\"Create index in the vector store (no-op for in-memory store).\"\"\"\n", |
| 160 | + " self.documents.clear()\n", |
| 161 | + " self.vectors.clear()\n", |
| 162 | + "\n", |
| 163 | + " print(f\"✅ Index '{self.index_name}' is ready in in-memory vector store\")\n", |
| 164 | + "\n", |
| 165 | + " def load_documents(self, documents: list[VectorStoreDocument]) -> None:\n", |
161 | 166 | " \"\"\"Load documents into the vector store.\"\"\"\n", |
162 | 167 | " if not self.connected:\n", |
163 | 168 | " msg = \"Vector store not connected. Call connect() first.\"\n", |
164 | 169 | " raise RuntimeError(msg)\n", |
165 | 170 | "\n", |
166 | | - " if overwrite:\n", |
167 | | - " self.documents.clear()\n", |
168 | | - " self.vectors.clear()\n", |
169 | | - "\n", |
170 | 171 | " loaded_count = 0\n", |
171 | 172 | " for doc in documents:\n", |
172 | 173 | " if doc.vector is not None:\n", |
|
230 | 231 | " # Use vector search with the embedding\n", |
231 | 232 | " return self.similarity_search_by_vector(query_embedding, k, **kwargs)\n", |
232 | 233 | "\n", |
233 | | - " def filter_by_id(self, include_ids: list[str] | list[int]) -> Any:\n", |
234 | | - " \"\"\"Build a query filter to filter documents by id.\n", |
235 | | - "\n", |
236 | | - " For this simple implementation, we return the list of IDs as the filter.\n", |
237 | | - " \"\"\"\n", |
238 | | - " return [str(id_) for id_ in include_ids]\n", |
239 | | - "\n", |
240 | 234 | " def search_by_id(self, id: str) -> VectorStoreDocument:\n", |
241 | 235 | " \"\"\"Search for a document by id.\"\"\"\n", |
242 | 236 | " doc_id = str(id)\n", |
|
281 | 275 | "CUSTOM_VECTOR_STORE_TYPE = \"simple_memory\"\n", |
282 | 276 | "\n", |
283 | 277 | "# Register the vector store class\n", |
284 | | - "VectorStoreFactory.register(CUSTOM_VECTOR_STORE_TYPE, SimpleInMemoryVectorStore)\n", |
| 278 | + "VectorStoreFactory().register(CUSTOM_VECTOR_STORE_TYPE, SimpleInMemoryVectorStore)\n", |
285 | 279 | "\n", |
286 | 280 | "print(f\"✅ Registered custom vector store with type: '{CUSTOM_VECTOR_STORE_TYPE}'\")\n", |
287 | 281 | "\n", |
288 | 282 | "# Verify registration\n", |
289 | | - "available_types = VectorStoreFactory.get_vector_store_types()\n", |
| 283 | + "available_types = VectorStoreFactory().keys()\n", |
290 | 284 | "print(f\"\\n📋 Available vector store types: {available_types}\")\n", |
291 | 285 | "print(\n", |
292 | | - " f\"🔍 Is our custom type supported? {VectorStoreFactory.is_supported_type(CUSTOM_VECTOR_STORE_TYPE)}\"\n", |
| 286 | + " f\"🔍 Is our custom type supported? {CUSTOM_VECTOR_STORE_TYPE in VectorStoreFactory()}\"\n", |
293 | 287 | ")" |
294 | 288 | ] |
295 | 289 | }, |
|
347 | 341 | "schema = VectorStoreSchemaConfig(index_name=\"test_collection\")\n", |
348 | 342 | "\n", |
349 | 343 | "# Create vector store instance using factory\n", |
350 | | - "vector_store = VectorStoreFactory.create_vector_store(\n", |
351 | | - " CUSTOM_VECTOR_STORE_TYPE, vector_store_schema_config=schema\n", |
| 344 | + "vector_store = VectorStoreFactory().create(\n", |
| 345 | + " CUSTOM_VECTOR_STORE_TYPE, {\"vector_store_schema_config\": schema}\n", |
352 | 346 | ")\n", |
353 | 347 | "\n", |
354 | 348 | "print(f\"✅ Created vector store instance: {type(vector_store).__name__}\")\n", |
|
363 | 357 | "source": [ |
364 | 358 | "# Connect and load documents\n", |
365 | 359 | "vector_store.connect()\n", |
| 360 | + "vector_store.create_index()\n", |
366 | 361 | "vector_store.load_documents(sample_documents)\n", |
367 | 362 | "\n", |
368 | 363 | "print(f\"📊 Updated stats: {vector_store.get_stats()}\")" |
|
472 | 467 | " # 1. GraphRAG creates vector store using factory\n", |
473 | 468 | " schema = VectorStoreSchemaConfig(index_name=\"graphrag_entities\")\n", |
474 | 469 | "\n", |
475 | | - " store = VectorStoreFactory.create_vector_store(\n", |
| 470 | + " store = VectorStoreFactory().create(\n", |
476 | 471 | " CUSTOM_VECTOR_STORE_TYPE,\n", |
477 | | - " vector_store_schema_config=schema,\n", |
478 | | - " similarity_threshold=0.3,\n", |
| 472 | + " {\"vector_store_schema_config\": schema, \"similarity_threshold\": 0.3},\n", |
479 | 473 | " )\n", |
480 | 474 | " store.connect()\n", |
481 | | - "\n", |
| 475 | + " store.create_index()\n", |
482 | 476 | " print(\"✅ Step 1: Vector store created and connected\")\n", |
483 | 477 | "\n", |
484 | 478 | " # 2. During indexing, GraphRAG loads extracted entities\n", |
|
534 | 528 | "\n", |
535 | 529 | " # Test 1: Basic functionality\n", |
536 | 530 | " print(\"Test 1: Basic functionality\")\n", |
537 | | - " store = VectorStoreFactory.create_vector_store(\n", |
| 531 | + " store = VectorStoreFactory().create(\n", |
538 | 532 | " CUSTOM_VECTOR_STORE_TYPE,\n", |
539 | | - " vector_store_schema_config=VectorStoreSchemaConfig(index_name=\"test\"),\n", |
| 533 | + " {\"vector_store_schema_config\": VectorStoreSchemaConfig(index_name=\"test\")},\n", |
540 | 534 | " )\n", |
541 | 535 | " store.connect()\n", |
542 | | - "\n", |
| 536 | + " store.create_index()\n", |
543 | 537 | " # Load test documents\n", |
544 | 538 | " test_docs = sample_documents[:2]\n", |
545 | 539 | " store.load_documents(test_docs)\n", |
|
575 | 569 | "\n", |
576 | 570 | " print(\"✅ Search by ID test passed\")\n", |
577 | 571 | "\n", |
578 | | - " # Test 4: Filter functionality\n", |
579 | | - " print(\"\\nTest 4: Filter functionality\")\n", |
580 | | - " filter_result = store.filter_by_id([\"doc_1\", \"doc_2\"])\n", |
581 | | - " assert filter_result == [\"doc_1\", \"doc_2\"], \"Should return filtered IDs\"\n", |
582 | | - " print(\"✅ Filter functionality test passed\")\n", |
583 | | - "\n", |
584 | | - " # Test 5: Error handling\n", |
| 572 | + " # Test 4: Error handling\n", |
585 | 573 | " print(\"\\nTest 5: Error handling\")\n", |
586 | | - " disconnected_store = VectorStoreFactory.create_vector_store(\n", |
| 574 | + " disconnected_store = VectorStoreFactory().create(\n", |
587 | 575 | " CUSTOM_VECTOR_STORE_TYPE,\n", |
588 | | - " vector_store_schema_config=VectorStoreSchemaConfig(index_name=\"test2\"),\n", |
| 576 | + " {\"vector_store_schema_config\": VectorStoreSchemaConfig(index_name=\"test2\")},\n", |
589 | 577 | " )\n", |
590 | 578 | "\n", |
591 | 579 | " try:\n", |
|
0 commit comments