File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
2+ import pymongo
3+ import time
4+ import os
5+ import pprint
6+
7+ CONNECTION_STRING = os .environ .get ("CONNECTION_STRING" )
8+ database_client = pymongo .MongoClient (CONNECTION_STRING )
9+ collection = database_client ["grocery_store" ]["inventory" ]
10+
11+ index_definition = {
12+ "name" : "vector_index" ,
13+ "type" : "vectorSearch" ,
14+ "definition" : {
15+ "fields" : [
16+ {
17+ "numDimensions" : 768 ,
18+ "path" : "gemini_embedding" ,
19+ "similarity" : "cosine" ,
20+ "type" : "vector"
21+ }
22+ ]
23+ }
24+ }
25+
26+ print ("Creating the vector search index..." )
27+ collection .create_search_index (index_definition )
28+
29+ print ("Waiting 10 seconds for the index to finish building..." )
30+ time .sleep (10 )
31+
32+ indexes = list (collection .list_search_indexes ())
33+ print ("Search indexes: " )
34+ pprint .pp (indexes )
You can’t perform that action at this time.
0 commit comments