本教程演示如何在本地实现检索增强生成 (RAG),而无需API密钥或信用。要学习;了解有关 RAG 的更多信息,请参阅 使用MongoDB进行检索增强生成 (RAG)。
具体来说,您需要执行以下操作:
创建本地 Atlas 部署。
设置环境。
使用本地嵌入模型生成向量嵌入。
对数据创建MongoDB Vector Search索引。
使用本地 LLM 来回答有关数据的问题。
先决条件
除了常见的先决条件外,本教程还需要以下内容:
创建本地部署
设置环境
使用本地模型生成嵌入
In this section, you load an embedding model locally and generate vector embeddings by using data from the sample_airbnb database, which contains a collection called listingsAndReviews.
This code might take several minutes to run. After it's finished, you can view your vector embeddings by connecting to your local deployment from mongosh or your application using your deployment's connection string. Then you can run read operations on the sample_airbnb.listingsAndReviews collection.
创建MongoDB Vector Search 索引
要在 sample_airbnb.listingsAndReviews集合上启用向量搜索,请创建MongoDB Vector Search索引。