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
@@ -3,7 +3,7 @@ NOTE: This vector database integration is community-supported and maintained on
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Optional
|
||||
from typing import Any, Optional
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from open_webui.config import (
|
||||
@@ -22,6 +22,7 @@ from open_webui.retrieval.vector.main import (
|
||||
VectorDBBase,
|
||||
VectorItem,
|
||||
)
|
||||
from open_webui.retrieval.vector.utils import iter_filter_conditions
|
||||
from qdrant_client import QdrantClient as Qclient
|
||||
from qdrant_client.http.models import PointStruct
|
||||
from qdrant_client.models import models
|
||||
@@ -31,6 +32,11 @@ NO_LIMIT = 999999999
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _metadata_filter(key: str, op: str, value: Any) -> models.FieldCondition:
|
||||
match = models.MatchAny(any=value) if op == '$in' else models.MatchValue(value=value)
|
||||
return models.FieldCondition(key=f'metadata.{key}', match=match)
|
||||
|
||||
|
||||
class QdrantClient(VectorDBBase):
|
||||
def __init__(self):
|
||||
self.collection_prefix = QDRANT_COLLECTION_PREFIX
|
||||
@@ -152,10 +158,13 @@ class QdrantClient(VectorDBBase):
|
||||
if limit is None:
|
||||
limit = NO_LIMIT # otherwise qdrant would set limit to 10!
|
||||
|
||||
conditions = [_metadata_filter(key, op, value) for key, op, value in iter_filter_conditions(filter)]
|
||||
query_filter = models.Filter(must=conditions) if conditions else None
|
||||
query_response = self.client.query_points(
|
||||
collection_name=f'{self.collection_prefix}_{collection_name}',
|
||||
query=vectors[0],
|
||||
limit=limit,
|
||||
query_filter=query_filter,
|
||||
)
|
||||
get_result = self._result_to_get_result(query_response.points)
|
||||
return SearchResult(
|
||||
|
||||
Reference in new issue
Block a user