Get started with Retrieval-Augmented Generation (RAG) and vector search using LangChain.js and Azure Cosmos DB.
- Document ingestion — Load text, split into chunks, and store vector embeddings in Azure Cosmos DB
- Semantic similarity search — Find relevant documents using vector similarity
- Score-threshold search — Filter results by similarity score
- MMR (Maximal Marginal Relevance) — Retrieve diverse, non-redundant results
- RAG chain — Answer questions using retrieved context with Azure OpenAI GPT-4.1
- Node.js v18 or later
- An Azure Cosmos DB account with NoSQL API
- An Azure OpenAI deployment with:
- A chat model (e.g.,
gpt-4.1) - An embedding model (e.g.,
text-embedding-3-small)
- A chat model (e.g.,
-
Clone the repo
git clone https://github.com/AzureCosmosDB/langchainjs-cosmosdb-rag-quickstart.git cd langchainjs-cosmosdb-rag-quickstart -
Install dependencies
npm install
-
Configure environment variables
cp .env.example .env
Edit
.envand fill in your Azure credentials. -
Run the sample
npm start
| File | Description |
|---|---|
get-started.js |
Main application — ingestion, search, and RAG |
sample-data.txt |
Sample document about Azure Cosmos DB |
.env.example |
Template for required environment variables |