2222 MARIADB_VECTOR_POOL_TIMEOUT ,
2323 MARIADB_VECTOR_POOL_RECYCLE ,
2424)
25- from open_webui .retrieval .vector .main import GetResult , SearchResult , VectorDBBase , VectorItem
25+ from open_webui .retrieval .vector .main import (
26+ GetResult ,
27+ SearchResult ,
28+ VectorDBBase ,
29+ VectorItem ,
30+ )
2631from open_webui .retrieval .vector .utils import process_metadata
2732
2833log = logging .getLogger (__name__ )
@@ -157,8 +162,7 @@ def _init_schema(self) -> None:
157162 with conn .cursor () as cur :
158163 try :
159164 dist = self .distance_strategy
160- cur .execute (
161- f"""
165+ cur .execute (f"""
162166 CREATE TABLE IF NOT EXISTS document_chunk (
163167 -- MariaDB Vector requires the table PRIMARY KEY used with a VECTOR INDEX to be <= 256 bytes.
164168 -- VARCHAR has internal length/metadata overhead, so VARCHAR(255) can exceed the 256-byte limit.
@@ -173,8 +177,7 @@ def _init_schema(self) -> None:
173177 VECTOR INDEX (embedding) M={ self .index_m } DISTANCE={ dist } ,
174178 INDEX idx_document_chunk_collection_name (collection_name)
175179 ) ENGINE=InnoDB;
176- """
177- )
180+ """ )
178181 conn .commit ()
179182 except Exception as e :
180183 conn .rollback ()
@@ -220,7 +223,11 @@ def _dist_fn(self) -> str:
220223 """
221224 Return the MariaDB Vector distance function name for the configured strategy.
222225 """
223- return "vec_distance_cosine" if self .distance_strategy == "cosine" else "vec_distance_euclidean"
226+ return (
227+ "vec_distance_cosine"
228+ if self .distance_strategy == "cosine"
229+ else "vec_distance_euclidean"
230+ )
224231
225232 def _score_from_dist (self , dist : float ) -> float :
226233 """
@@ -442,12 +449,19 @@ def search(
442449 documents [q_idx ].append (rtext )
443450 metadatas [q_idx ].append (_safe_json (rmeta ))
444451
445- return SearchResult (ids = ids , distances = distances , documents = documents , metadatas = metadatas )
452+ return SearchResult (
453+ ids = ids ,
454+ distances = distances ,
455+ documents = documents ,
456+ metadatas = metadatas ,
457+ )
446458 except Exception as e :
447459 log .exception (f"[MARIADB_VECTOR] search() failed: { e } " )
448460 return None
449461
450- def query (self , collection_name : str , filter : Dict [str , Any ], limit : Optional [int ] = None ) -> Optional [GetResult ]:
462+ def query (
463+ self , collection_name : str , filter : Dict [str , Any ], limit : Optional [int ] = None
464+ ) -> Optional [GetResult ]:
451465 """
452466 Retrieve documents by metadata filter (non-vector query).
453467 """
@@ -472,7 +486,9 @@ def query(self, collection_name: str, filter: Dict[str, Any], limit: Optional[in
472486 metadatas = [[_safe_json (r [2 ]) for r in rows ]]
473487 return GetResult (ids = ids , documents = documents , metadatas = metadatas )
474488
475- def get (self , collection_name : str , limit : Optional [int ] = None ) -> Optional [GetResult ]:
489+ def get (
490+ self , collection_name : str , limit : Optional [int ] = None
491+ ) -> Optional [GetResult ]:
476492 """
477493 Retrieve documents in a collection without filtering (optionally limited).
478494 """
@@ -549,7 +565,10 @@ def has_collection(self, collection_name: str) -> bool:
549565 try :
550566 with self ._connect () as conn :
551567 with conn .cursor () as cur :
552- cur .execute ("SELECT 1 FROM document_chunk WHERE collection_name = ? LIMIT 1" , (collection_name ,))
568+ cur .execute (
569+ "SELECT 1 FROM document_chunk WHERE collection_name = ? LIMIT 1" ,
570+ (collection_name ,),
571+ )
553572 return cur .fetchone () is not None
554573 except Exception :
555574 return False
0 commit comments