Saiteja Solleti commited on
Commit
cf42161
·
1 Parent(s): 5dce073
Files changed (1) hide show
  1. createmilvusschema.py +15 -13
createmilvusschema.py CHANGED
@@ -32,17 +32,19 @@ def CreateMilvusDbSchema():
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
 
32
  # Create the collection in Milvus
33
  collection = Collection(name=COLLECTION_NAME, schema=schema)
34
 
35
+ try:
36
+ # Create an optimized index for fast vector search
37
+ collection.create_index(
38
+ "chunk_embedding",
39
+ {
40
+ "index_type": "HNSW", # Hierarchical Navigable Small World (HNSW) index
41
+ "metric_type": "COSINE", # Cosine similarity for vector search
42
+ "params": {"M": 16, "efConstruction": 200} # HNSW parameters
43
+ }
44
+ )
45
  print("Index created successfully.")
46
+ print(f"Collection '{COLLECTION_NAME}' created successfully.")
47
+ except Exception as e:
48
+ print(f"Failed to create index: {e}")
49
+ finally:
50
+ return collection