Skip to content

Commit a0d1d64

Browse files
fix(brains+milvus): fixed brain_id + milvus index creation error
1 parent e77a86a commit a0d1d64

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "brainapi2"
3-
version = "1.6.14-dev"
3+
version = "1.6.16-dev"
44
description = "Version 1.x.x of the BrainAPI memory layer."
55
authors = [
66
{name = "Christian",email = "[email protected]"}

src/lib/milvus/client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,28 @@ def _ensure_store(self, store: str, brain_id: str) -> None:
9292
if store not in EMBEDDING_STORES_SIZES:
9393
raise ValueError(f"Store {store} not available")
9494

95+
collection_created = False
9596
if not self.client.has_collection(store):
9697
self.client.create_collection(
9798
store,
9899
dimension=EMBEDDING_STORES_SIZES[store],
99100
vector_field_name="embeddings",
100101
)
102+
collection_created = True
103+
104+
if collection_created:
105+
try:
106+
index_params = {
107+
"metric_type": "COSINE",
108+
"index_type": "AUTOINDEX",
109+
}
110+
self.client.create_index(
111+
collection_name=store,
112+
field_name="embeddings",
113+
index_params=index_params,
114+
)
115+
except Exception as e:
116+
pass
101117

102118
try:
103119
has_partition = self.client.has_partition(store, brain_id)

src/services/api/middlewares/brains.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,21 @@ async def receive():
8282
if brain_id and not cached_brain_id:
8383
stored_brain = data_adapter.get_brain(name_key=brain_id)
8484

85+
request.state.brain_id = brain_id
86+
8587
if not stored_brain and brain_creation_allowed:
8688
new_brain = data_adapter.create_brain(name_key=brain_id)
8789
cache_adapter.set(
8890
key=f"brain:{brain_id}",
8991
value=new_brain.id,
9092
brain_id="system",
9193
)
92-
request.state.brain_id = new_brain.id
9394
elif stored_brain:
9495
cache_adapter.set(
9596
key=f"brain:{brain_id}",
9697
value=stored_brain.id,
9798
brain_id="system",
9899
)
99-
request.state.brain_id = stored_brain.id
100100
elif not brain_id and default_brain_fallback:
101101
default_brain = data_adapter.get_brain(name_key="default")
102102
if not default_brain:

0 commit comments

Comments
 (0)