@@ -104,8 +104,8 @@ from crossvector.dbs.astradb import AstraDBAdapter
104104
105105# Initialize engine
106106engine = VectorEngine(
107- embedding_adapter = OpenAIEmbeddingAdapter( model_name = " text-embedding-3-small " ),
108- db_adapter = AstraDBAdapter( ),
107+ db = AstraDBAdapter( ),
108+ embedding = OpenAIEmbeddingAdapter( model_name = " text-embedding-3-small " ),
109109 collection_name = " my_documents" ,
110110 store_text = True # Optional: Set to False to not store original text
111111)
@@ -121,9 +121,9 @@ print(f"Inserted {len(docs)} documents")
121121# Alternative: Upsert with VectorDocument (if you have embeddings already)
122122vector_docs = [
123123 VectorDocument(
124- id = " doc3" ,
125- text = " Python programming" ,
126- vector = [0.1 ]* 1536 ,
124+ id = " doc3" ,
125+ text = " Python programming" ,
126+ vector = [0.1 ]* 1536 ,
127127 metadata = {" category" : " tech" }
128128 )
129129]
@@ -269,14 +269,14 @@ from typing import Any, Dict, List, Set, Optional, Union, Sequence, Tuple
269269
270270class MyCustomDBAdapter (VectorDBAdapter ):
271271 """ Custom vector database adapter implementation."""
272-
272+
273273 # Optional: Set to True if your database uses '$vector' instead of 'vector'
274274 use_dollar_vector: bool = False
275-
275+
276276 def initialize (
277- self ,
278- collection_name : str ,
279- embedding_dimension : int ,
277+ self ,
278+ collection_name : str ,
279+ embedding_dimension : int ,
280280 metric : str = " cosine" ,
281281 ** kwargs : Any
282282 ) -> None :
@@ -285,9 +285,9 @@ class MyCustomDBAdapter(VectorDBAdapter):
285285 pass
286286
287287 def add_collection (
288- self ,
289- collection_name : str ,
290- embedding_dimension : int ,
288+ self ,
289+ collection_name : str ,
290+ embedding_dimension : int ,
291291 metric : str = " cosine"
292292 ) -> Any:
293293 """ Create a new collection."""
@@ -300,9 +300,9 @@ class MyCustomDBAdapter(VectorDBAdapter):
300300 pass
301301
302302 def get_or_create_collection (
303- self ,
304- collection_name : str ,
305- embedding_dimension : int ,
303+ self ,
304+ collection_name : str ,
305+ embedding_dimension : int ,
306306 metric : str = " cosine"
307307 ) -> Any:
308308 """ Get existing collection or create if doesn't exist."""
@@ -343,15 +343,8 @@ class MyCustomDBAdapter(VectorDBAdapter):
343343 # Should return VectorDocument instance
344344 pass
345345
346- def get_or_create (
347- self ,
348- defaults : Optional[Dict[str , Any]] = None ,
349- ** kwargs
350- ) -> Tuple[VectorDocument, bool ]:
351- """ Get document by pk or create if not found."""
352- # Your implementation
353- # Should return (VectorDocument, created: bool)
354- pass
346+ # NOTE : get_or_create has been centralized in VectorEngine.
347+ # Adapters no longer implement this to avoid duplicated logic.
355348
356349 def create (self , ** kwargs : Any) -> VectorDocument:
357350 """ Create and persist a single document."""
@@ -384,16 +377,8 @@ class MyCustomDBAdapter(VectorDBAdapter):
384377 # Should return updated VectorDocument instance
385378 pass
386379
387- def update_or_create (
388- self ,
389- defaults : Optional[Dict[str , Any]] = None ,
390- create_defaults : Optional[Dict[str , Any]] = None ,
391- ** kwargs
392- ) -> Tuple[VectorDocument, bool ]:
393- """ Update document if exists, otherwise create."""
394- # Your implementation
395- # Should return (VectorDocument, created: bool)
396- pass
380+ # NOTE : update_or_create has been centralized in VectorEngine.
381+ # Adapters no longer implement this to avoid duplicated logic.
397382
398383 def bulk_update (
399384 self ,
@@ -408,8 +393,8 @@ class MyCustomDBAdapter(VectorDBAdapter):
408393 pass
409394
410395 def upsert (
411- self ,
412- documents : List[VectorDocument],
396+ self ,
397+ documents : List[VectorDocument],
413398 batch_size : int = None
414399 ) -> List[VectorDocument]:
415400 """ Insert new documents or update existing ones."""
@@ -668,8 +653,8 @@ from crossvector.embeddings.openai import OpenAIEmbeddingAdapter
668653from crossvector.dbs.pgvector import PGVectorAdapter
669654
670655engine = VectorEngine(
671- embedding_adapter = OpenAIEmbeddingAdapter (),
672- db_adapter = PGVectorAdapter (),
656+ db = PGVectorAdapter (),
657+ embedding = OpenAIEmbeddingAdapter (),
673658 collection_name = " docs" ,
674659 store_text = True
675660)
0 commit comments