Skip to content

Commit 11facd2

Browse files
committed
Fix Qdrant collection alias creation
This PR resolves an issue where the system would crash during collection creation if a timeout occurred. Previously, when the collection creation timed out, no alias was created, and the subsequent check would fail when trying to access the first element of an empty aliases list. Changes: * Improved alias checking by verifying existence before comparison * Added try-catch blocks in collection creation with helpful error messages suggesting timeout increase
1 parent 086778c commit 11facd2

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

core/cat/memory/vector_memory_collection.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def check_embedding_size(self):
5959
== self.embedder_size
6060
)
6161
alias = self.embedder_name + "_" + self.collection_name
62-
if (
63-
alias
64-
== self.client.get_collection_aliases(self.collection_name)
65-
.aliases[0]
66-
.alias_name
62+
63+
existing_aliases = self.client.get_collection_aliases(self.collection_name).aliases
64+
65+
if ( len(existing_aliases) > 0 and
66+
alias == existing_aliases[0].alias_name
6767
and same_size
6868
):
6969
log.debug(f'Collection "{self.collection_name}" has the same embedder')
@@ -94,31 +94,48 @@ def create_db_collection_if_not_exists(self):
9494

9595
# create collection
9696
def create_collection(self):
97-
log.warning(f'Creating collection "{self.collection_name}" ...')
98-
self.client.create_collection(
99-
collection_name=self.collection_name,
100-
vectors_config=VectorParams(
101-
size=self.embedder_size, distance=Distance.COSINE
102-
),
103-
# hybrid mode: original vector on Disk, quantized vector in RAM
104-
optimizers_config=OptimizersConfigDiff(memmap_threshold=20000),
105-
quantization_config=ScalarQuantization(
106-
scalar=ScalarQuantizationConfig(
107-
type=ScalarType.INT8, quantile=0.95, always_ram=True
108-
)
109-
),
110-
)
111-
112-
self.client.update_collection_aliases(
113-
change_aliases_operations=[
114-
CreateAliasOperation(
115-
create_alias=CreateAlias(
116-
collection_name=self.collection_name,
117-
alias_name=self.embedder_name + "_" + self.collection_name,
97+
try:
98+
log.warning(f'Creating collection "{self.collection_name}" ...')
99+
self.client.create_collection(
100+
collection_name=self.collection_name,
101+
vectors_config=VectorParams(
102+
size=self.embedder_size, distance=Distance.COSINE
103+
),
104+
# hybrid mode: original vector on Disk, quantized vector in RAM
105+
optimizers_config=OptimizersConfigDiff(memmap_threshold=20000),
106+
quantization_config=ScalarQuantization(
107+
scalar=ScalarQuantizationConfig(
108+
type=ScalarType.INT8, quantile=0.95, always_ram=True
118109
)
119-
)
120-
]
121-
)
110+
),
111+
)
112+
except Exception as e:
113+
log.error(f"Error creating collection {self.collection_name}. Try setting a higher timeout value in CCAT_QDRANT_CLIENT_TIMEOUT: {e}")
114+
self.client.delete_collection(self.collection_name)
115+
raise
116+
117+
try:
118+
alias_name=self.embedder_name + "_" + self.collection_name
119+
log.warning(f'Creating alias {alias_name} for collection "{self.collection_name}" ...')
120+
121+
self.client.update_collection_aliases(
122+
change_aliases_operations=[
123+
CreateAliasOperation(
124+
create_alias=CreateAlias(
125+
collection_name=self.collection_name,
126+
alias_name=alias_name,
127+
)
128+
)
129+
]
130+
)
131+
132+
log.warning(f'Created alias {alias_name} for collection "{self.collection_name}" ...')
133+
except Exception as e:
134+
log.error(f"Error creating collection alias {alias_name} for collection {self.collection_name}: {e}")
135+
self.client.delete_collection(self.collection_name)
136+
log.error(f" collection {self.collection_name} deleted")
137+
raise
138+
122139

123140
# adapted from https://github.com/langchain-ai/langchain/blob/bfc12a4a7644cfc4d832cc4023086a7a5374f46a/libs/langchain/langchain/vectorstores/qdrant.py#L1965
124141
def _qdrant_filter_from_dict(self, filter: dict) -> Filter:

0 commit comments

Comments
 (0)