Using MongoDB Atlas as a Vector Store with OpenAI Embeddings
This project illustrates how to leverage MongoDB as a vector store for performing similarity searches, utilizing OpenAI embeddings within a Go application. It integrates the LangChainGo library, OpenAI's API, and MongoDB to create an efficient vector database for semantic search.
Connects to a MongoDB Atlas instance using a specified connection string.
Automatically checks for and creates a vector search index on the collection if it is not already present, ensuring compatibility with OpenAI's embedding model.
OpenAI Embeddings Initialization:
Establishes an embeddings client through the OpenAI API.
Requires the OpenAI API key to be set as an environment variable for authentication.
Creating the Vector Store:
Connects to the MongoDB database and sets up a vector store that utilizes OpenAI embeddings for document representation.
Inserting Sample Data:
Adds a collection of documents (cities) along with their metadata into the vector store.
Each document contains information such as the city name, population, and area.
Executing Similarity Searches:
Demonstrates various types of similarity searches.
Running the Example
Configure your environment by setting the MongoDB URI and OpenAI API key: