2023年6月mongodb新版发布增加了向量检索的功能,全面拥抱ai
创建向量索引
{ "type": "vectorSearch, "fields": [{ "path": "plot_embedding_hf", "dimensions": 384, "similarity": "dotProduct", "type": "vector" }] }RAG检索
query = "imaginary characters from outer space at war" results = collection.aggregate([ {"$vectorSearch": { "queryVector": generate_embedding(query), "path": "plot_embedding_hf", "numCandidates": 100, "limit": 4, "index": "PlotSemanticSearch", }} }); for document in results: print(f'Movie Name: {document["title"]},\nMovie Plot: {document["plot"]}\n')
官方教程
https://www.mongodb.com/developer/products/atlas/building-generative-ai-applications-vector-search-open-source-models/
网友回复