Spaces:
Sleeping
Sleeping
Saiteja Solleti
commited on
Commit
·
ba6792e
1
Parent(s):
408ab70
index check changes
Browse files- createmilvusschema.py +7 -5
createmilvusschema.py
CHANGED
@@ -32,15 +32,17 @@ def CreateMilvusDbSchema():
|
|
32 |
# Create the collection in Milvus
|
33 |
collection = Collection(name=COLLECTION_NAME, schema=schema)
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
{
|
39 |
"index_type": "HNSW", # Hierarchical Navigable Small World (HNSW) index
|
40 |
"metric_type": "COSINE", # Cosine similarity for vector search
|
41 |
"params": {"M": 16, "efConstruction": 200} # HNSW parameters
|
42 |
}
|
43 |
-
|
|
|
|
|
|
|
44 |
|
45 |
print(f"Collection '{COLLECTION_NAME}' created successfully.")
|
46 |
return collection
|
|
|
32 |
# Create the collection in Milvus
|
33 |
collection = Collection(name=COLLECTION_NAME, schema=schema)
|
34 |
|
35 |
+
if not collection.indexes:
|
36 |
+
print("Creating index for fast vector search...")
|
37 |
+
index_params = {
|
|
|
38 |
"index_type": "HNSW", # Hierarchical Navigable Small World (HNSW) index
|
39 |
"metric_type": "COSINE", # Cosine similarity for vector search
|
40 |
"params": {"M": 16, "efConstruction": 200} # HNSW parameters
|
41 |
}
|
42 |
+
collection.create_index(field_name="chunk_embedding", index_params=index_params)
|
43 |
+
print("Index created successfully.")
|
44 |
+
else:
|
45 |
+
print("Index already exists: ", collection.indexes)
|
46 |
|
47 |
print(f"Collection '{COLLECTION_NAME}' created successfully.")
|
48 |
return collection
|