2121class LanceDBVectorStore (BaseVectorStore ):
2222 """LanceDB vector storage implementation."""
2323
24- def __init__ (self , vector_store_schema_config : VectorStoreSchemaConfig , ** kwargs : Any ) -> None :
25- super ().__init__ (vector_store_schema_config = vector_store_schema_config , ** kwargs )
24+ def __init__ (
25+ self , vector_store_schema_config : VectorStoreSchemaConfig , ** kwargs : Any
26+ ) -> None :
27+ super ().__init__ (
28+ vector_store_schema_config = vector_store_schema_config , ** kwargs
29+ )
2630
2731 def connect (self , ** kwargs : Any ) -> Any :
2832 """Connect to the vector storage."""
2933 self .db_connection = lancedb .connect (kwargs ["db_uri" ])
3034
31- if (
32- self .index_name
33- and self .index_name in self .db_connection .table_names ()
34- ):
35- self .document_collection = self .db_connection .open_table (
36- self .index_name
37- )
38-
35+ if self .index_name and self .index_name in self .db_connection .table_names ():
36+ self .document_collection = self .db_connection .open_table (self .index_name )
3937
4038 def load_documents (
4139 self , documents : list [VectorStoreDocument ], overwrite : bool = True
@@ -61,14 +59,16 @@ def load_documents(
6159 # Step 3: Flatten the vectors and build FixedSizeListArray manually
6260 flat_vector = np .concatenate (vectors ).astype (np .float32 )
6361 flat_array = pa .array (flat_vector , type = pa .float32 ())
64- vector_column = pa .FixedSizeListArray .from_arrays (flat_array , self .vector_size )
62+ vector_column = pa .FixedSizeListArray .from_arrays (
63+ flat_array , self .vector_size
64+ )
6565
6666 # Step 4: Create PyArrow table (let schema be inferred)
6767 data = pa .table ({
6868 self .id_field : pa .array (ids , type = pa .string ()),
6969 self .text_field : pa .array (texts , type = pa .string ()),
7070 self .vector_field : vector_column ,
71- self .attributes_field : pa .array (attributes , type = pa .string ())
71+ self .attributes_field : pa .array (attributes , type = pa .string ()),
7272 })
7373
7474 # NOTE: If modifying the next section of code, ensure that the schema remains the same.
@@ -83,12 +83,12 @@ def load_documents(
8383 self .document_collection = self .db_connection .create_table (
8484 self .index_name , mode = "overwrite"
8585 )
86- self .document_collection .create_index (vector_column_name = self .vector_field , index_type = "IVF_FLAT" )
86+ self .document_collection .create_index (
87+ vector_column_name = self .vector_field , index_type = "IVF_FLAT"
88+ )
8789 else :
8890 # add data to existing table
89- self .document_collection = self .db_connection .open_table (
90- self .index_name
91- )
91+ self .document_collection = self .db_connection .open_table (self .index_name )
9292 if data :
9393 self .document_collection .add (data )
9494
0 commit comments