Fix indexing when using Qdrant cloud (#3228)
This commit is contained in:
@@ -48,6 +48,7 @@ class Qdrant(VectorStoreBase):
|
||||
"""
|
||||
if client:
|
||||
self.client = client
|
||||
self.is_local = False
|
||||
else:
|
||||
params = {}
|
||||
if api_key:
|
||||
@@ -57,11 +58,15 @@ class Qdrant(VectorStoreBase):
|
||||
if host and port:
|
||||
params["host"] = host
|
||||
params["port"] = port
|
||||
|
||||
if not params:
|
||||
params["path"] = path
|
||||
self.is_local = True
|
||||
if not on_disk:
|
||||
if os.path.exists(path) and os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
self.is_local = False
|
||||
|
||||
self.client = QdrantClient(**params)
|
||||
|
||||
@@ -84,12 +89,34 @@ class Qdrant(VectorStoreBase):
|
||||
for collection in response.collections:
|
||||
if collection.name == self.collection_name:
|
||||
logger.debug(f"Collection {self.collection_name} already exists. Skipping creation.")
|
||||
self._create_filter_indexes()
|
||||
return
|
||||
|
||||
self.client.create_collection(
|
||||
collection_name=self.collection_name,
|
||||
vectors_config=VectorParams(size=vector_size, distance=distance, on_disk=on_disk),
|
||||
)
|
||||
self._create_filter_indexes()
|
||||
|
||||
def _create_filter_indexes(self):
|
||||
"""Create indexes for commonly used filter fields to enable filtering."""
|
||||
# Only create payload indexes for remote Qdrant servers
|
||||
if self.is_local:
|
||||
logger.debug("Skipping payload index creation for local Qdrant (not supported)")
|
||||
return
|
||||
|
||||
common_fields = ["user_id", "agent_id", "run_id", "actor_id"]
|
||||
|
||||
for field in common_fields:
|
||||
try:
|
||||
self.client.create_payload_index(
|
||||
collection_name=self.collection_name,
|
||||
field_name=field,
|
||||
field_schema="keyword"
|
||||
)
|
||||
logger.info(f"Created index for {field} in collection {self.collection_name}")
|
||||
except Exception as e:
|
||||
logger.debug(f"Index for {field} might already exist: {e}")
|
||||
|
||||
def insert(self, vectors: list, payloads: list = None, ids: list = None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user