87 lines
2.5 KiB
Markdown
87 lines
2.5 KiB
Markdown
# RAG Agent with ChromaDB and Web Search
|
||
|
||
This project implements a Retrieval-Augmented Generation (RAG) agent that:
|
||
- Stores and retrieves embeddings from **ChromaDB**.
|
||
- Performs web search using DuckDuckGo to fetch additional context.
|
||
- Generates answers with an **Ollama** language model.
|
||
|
||
## Prerequisites
|
||
|
||
- Node.js v20 or newer
|
||
- ChromaDB server running locally (default URL: `chromadb://localhost:8000`)
|
||
- Ollama server running locally (default URL: `http://localhost:11434`)
|
||
|
||
## Setup
|
||
|
||
1. **Clone the repository**
|
||
|
||
```bash
|
||
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-rag-agent-s-chromadb-i-veb-poisk.git
|
||
cd ekzamen-rag-agent-s-chromadb-i-veb-poisk
|
||
```
|
||
|
||
2. **Install dependencies**
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
3. **Configure environment variables**
|
||
|
||
Create a `.env` file in the project root (or modify the existing one):
|
||
|
||
```dotenv
|
||
CHROMA_URL=chromadb://localhost:8000
|
||
CHROMA_COLLECTION=rag_collection
|
||
OLLAMA_HOST=http://localhost:11434
|
||
OLLAMA_MODEL=llama3
|
||
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
|
||
ADD_SAMPLE_DOCS=true
|
||
```
|
||
|
||
- `CHROMA_URL`: URL of your ChromaDB instance.
|
||
- `CHROMA_COLLECTION`: Name of the collection to use.
|
||
- `OLLAMA_HOST`: URL of your Ollama server.
|
||
- `OLLAMA_MODEL`: Ollama model for generation.
|
||
- `OLLAMA_EMBEDDING_MODEL`: Ollama model for embeddings.
|
||
- `ADD_SAMPLE_DOCS`: Set to `true` to automatically add a few sample documents on startup.
|
||
|
||
4. **Run the agent**
|
||
|
||
```bash
|
||
npm start -- "Your question here"
|
||
```
|
||
|
||
Example:
|
||
|
||
```bash
|
||
npm start -- "What is LangChain?"
|
||
```
|
||
|
||
The agent will:
|
||
- Search the local ChromaDB collection.
|
||
- Perform a DuckDuckGo web search.
|
||
- Combine the results and generate an answer using Ollama.
|
||
|
||
## Project Structure
|
||
|
||
```
|
||
.
|
||
├── src
|
||
│ ├── agent.js # Agent logic (retrieval + generation)
|
||
│ ├── index.js # CLI entry point
|
||
│ ├── vectorStore.js # ChromaDB wrapper
|
||
│ └── webSearch.js # DuckDuckGo search helper
|
||
├── .env # Environment configuration
|
||
├── package.json # Dependencies and scripts
|
||
└── README.md # Documentation
|
||
```
|
||
|
||
## Notes
|
||
|
||
- The agent uses **LangChain 1.x** APIs.
|
||
- No Qdrant references are present; only ChromaDB is used.
|
||
- The web search is performed via DuckDuckGo’s public JSON API (no API key required).
|
||
- The Ollama LLM is used for both embeddings and generation.
|
||
|
||
Feel free to extend the agent with additional retrievers or custom prompts as needed. |