How can i create a vector search index using pymongo. It returns command not found when i give this. I have already inserted the document field with the text embeddings
Could you share what version and tier of Atlas is running?
If you are running on an M0 (free shared) cluster, creating search indexes via the pymongo driver is not yet supported, so it will need to be done via the Atlas webpage.
However, if you are operating on something higher than an M0, please ensure that you are running on the most recent minor release of Atlas 6.0, or 7.0. Otherwise, you can expect similar behavior to an M0.
Thank you for pointinf it out. It was misleading because OP mentioned create_vectore_search, which is actually what I am looking for. I tried to use this command to create a search index of type vector, but it only creates a vector search. Is this even supported (yet) ?
If I understand your question correctly, the configuration you provided should work when you store it in the pymongo.operations.SearchIndexModel object.
Also, the method create_vector_search does not exist.
The method you should use instead is collection.create_search_index this method supports what you are hoping to achieve with create_vector_search .
Hi @Jib_Adegunloye , Thank you for helping. I indeed you the model from from pymongo.operations import SearchIndexModel
Also I noticed the method did not exists and I tried to use the one you mention instead. However this lead to creating a an index with the wrong type format (“search” instead of “vector”). As you can see in the picture attach. The first one is incorrect and creating with pymongo. The second one is correct and creating with the same parameters from the mongocloud GUI
Hey @Matthieu_Mazzolini , apologies for the delay here.
To execute the command via pymongo and have an type: vectorSearch index. For now, you will need to use the Database.command method and createSearchIndexes. Link to docs.
Here’s an example using your current configuration:
I am running into the same issue (command not found code 59), using pymongo 4.6.3 and motor 3.4.0. This is running against an M0 tier Atlas database, which is on MongoDB 7.0.8 right now.
I used @Jib_Adegunloye code to see if it would fix things, but it is the same error. Originally I was using pymongo’s create_search_index and SearchIndexModel with the same results.
I believe this is exactly the search index I have already created with the UI and it works in all my queries and such. I just need to create with code so it is more maintainable, and it works in all my scenarios (automation, new deployments, etc.).
Hi @WarpedPixel and @Matthieu_Mazzolini - What tier of Atlas cluster are you using? The create_search_index command mentioned above can be used with M10+ cluster version only currently-
Thanks. The feature works and is implemented in the UI, and the Atlas M0 deployment is running the right version of MongoDB now (7+), but the API is limited. Hopefully it is a deployment lag issue, and not some business decision that will remain this way.
Perhaps the API error case is not implemented correctly to limit to 3 indices in an M0 tier? That limitation is in the UI for M0, and the easiest thing for the API was to just disable it completely for M0 until the 3 index limit could be done robustly in the API. That would make sense.