Fix indexing when using Qdrant cloud (#3228)
This commit is contained in:
@@ -48,6 +48,7 @@ class Qdrant(VectorStoreBase):
|
|||||||
"""
|
"""
|
||||||
if client:
|
if client:
|
||||||
self.client = client
|
self.client = client
|
||||||
|
self.is_local = False
|
||||||
else:
|
else:
|
||||||
params = {}
|
params = {}
|
||||||
if api_key:
|
if api_key:
|
||||||
@@ -57,11 +58,15 @@ class Qdrant(VectorStoreBase):
|
|||||||
if host and port:
|
if host and port:
|
||||||
params["host"] = host
|
params["host"] = host
|
||||||
params["port"] = port
|
params["port"] = port
|
||||||
|
|
||||||
if not params:
|
if not params:
|
||||||
params["path"] = path
|
params["path"] = path
|
||||||
|
self.is_local = True
|
||||||
if not on_disk:
|
if not on_disk:
|
||||||
if os.path.exists(path) and os.path.isdir(path):
|
if os.path.exists(path) and os.path.isdir(path):
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
else:
|
||||||
|
self.is_local = False
|
||||||
|
|
||||||
self.client = QdrantClient(**params)
|
self.client = QdrantClient(**params)
|
||||||
|
|
||||||
@@ -84,12 +89,34 @@ class Qdrant(VectorStoreBase):
|
|||||||
for collection in response.collections:
|
for collection in response.collections:
|
||||||
if collection.name == self.collection_name:
|
if collection.name == self.collection_name:
|
||||||
logger.debug(f"Collection {self.collection_name} already exists. Skipping creation.")
|
logger.debug(f"Collection {self.collection_name} already exists. Skipping creation.")
|
||||||
|
self._create_filter_indexes()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.client.create_collection(
|
self.client.create_collection(
|
||||||
collection_name=self.collection_name,
|
collection_name=self.collection_name,
|
||||||
vectors_config=VectorParams(size=vector_size, distance=distance, on_disk=on_disk),
|
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):
|
def insert(self, vectors: list, payloads: list = None, ids: list = None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user