refac
Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
1 parent
067114c280
commit
1d6d4e6e66
12 files changed
+191
-35
No files matched your search
@@ -68,7 +68,7 @@ from open_webui.retrieval.vector.main import (
|
||||
VectorDBBase,
|
||||
VectorItem,
|
||||
)
|
||||
from open_webui.retrieval.vector.utils import process_metadata
|
||||
from open_webui.retrieval.vector.utils import iter_filter_conditions, process_metadata
|
||||
|
||||
VECTOR_LENGTH = OPENGAUSS_INITIALIZE_MAX_VECTOR_LENGTH
|
||||
Base = declarative_base()
|
||||
@@ -86,6 +86,12 @@ class DocumentChunk(Base):
|
||||
vmetadata = Column(MutableDict.as_mutable(JSONB), nullable=True)
|
||||
|
||||
|
||||
def _metadata_clause(key: str, op: str, value: Any):
|
||||
if op == '$in':
|
||||
return DocumentChunk.vmetadata[key].astext.in_([str(v) for v in value])
|
||||
return DocumentChunk.vmetadata[key].astext == str(value)
|
||||
|
||||
|
||||
class OpenGaussClient(VectorDBBase):
|
||||
def __init__(self) -> None:
|
||||
if not OPENGAUSS_DB_URL:
|
||||
@@ -242,10 +248,15 @@ class OpenGaussClient(VectorDBBase):
|
||||
DocumentChunk.vmetadata,
|
||||
(DocumentChunk.vector.cosine_distance(query_vectors.c.q_vector)).label('distance'),
|
||||
]
|
||||
where_clauses = [DocumentChunk.collection_name == collection_name]
|
||||
if filter:
|
||||
where_clauses.extend(
|
||||
_metadata_clause(key, op, value) for key, op, value in iter_filter_conditions(filter)
|
||||
)
|
||||
|
||||
subq = (
|
||||
select(*result_fields)
|
||||
.where(DocumentChunk.collection_name == collection_name)
|
||||
.where(*where_clauses)
|
||||
.order_by(DocumentChunk.vector.cosine_distance(query_vectors.c.q_vector))
|
||||
)
|
||||
if limit is not None:
|
||||
|
||||
Reference in new issue
Block a user