feat: solution for 'Экзамен: RAG-агент с ChromaDB и веб-поиском'
This commit is contained in:
@@ -1,82 +1,61 @@
|
||||
# RAG Agent with ChromaDB and Web Search
|
||||
|
||||
This project implements a Retrieval-Augmented Generation (RAG) agent that uses **ChromaDB** as the vector store and performs web search to ingest documents. The agent answers user questions by retrieving relevant passages from the stored documents and generating responses with OpenAI’s GPT models.
|
||||
This project demonstrates a simple Retrieval-Augmented Generation (RAG) agent that uses **ChromaDB** for vector storage and similarity search, and performs web search using DuckDuckGo.
|
||||
|
||||
## Features
|
||||
|
||||
- **ChromaDB** vector store (no Qdrant usage)
|
||||
- Web content ingestion via HTTP fetch
|
||||
- OpenAI embeddings for vector representation
|
||||
- GPT-4o-mini for answer generation
|
||||
- Simple CLI usage
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Node.js 20+ (ESM support)
|
||||
- Docker (optional, for running ChromaDB locally)
|
||||
- OpenAI API key
|
||||
- **Vector Store**: Stores embeddings in a local ChromaDB collection.
|
||||
- **RAG Agent**: Retrieves relevant documents and constructs an answer.
|
||||
- **Web Search**: Fetches top results from DuckDuckGo.
|
||||
|
||||
## Setup
|
||||
|
||||
1. **Clone the repository**
|
||||
```bash
|
||||
# Clone the repository
|
||||
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
|
||||
|
||||
```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
|
||||
```
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
2. **Install dependencies**
|
||||
# Run the example
|
||||
npm start
|
||||
```
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
## Running Tests
|
||||
|
||||
3. **Configure environment variables**
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
Create a `.env` file in the project root:
|
||||
## Configuration
|
||||
|
||||
```dotenv
|
||||
CHROMA_HOST=localhost
|
||||
CHROMA_PORT=8000
|
||||
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
|
||||
```
|
||||
The project uses a local ChromaDB instance by default. If you need to connect to a remote instance, set the following environment variables in a `.env` file:
|
||||
|
||||
4. **Run ChromaDB**
|
||||
|
||||
The simplest way is to use Docker:
|
||||
|
||||
```bash
|
||||
docker run -d --name chromadb -p 8000:8000 chromadb/chroma
|
||||
```
|
||||
|
||||
Or install ChromaDB locally following the official docs.
|
||||
|
||||
5. **Run the agent**
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
The script will ingest a sample document from GitHub and answer a question about the OpenAI Node.js library.
|
||||
```dotenv
|
||||
CHROMA_HOST=localhost
|
||||
CHROMA_PORT=8000
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
src/
|
||||
├── agent.js # RAG agent logic
|
||||
├── index.js # Entry point
|
||||
├── vectorStore.js # ChromaDB wrapper
|
||||
└── webSearch.js # Simple web fetch helper
|
||||
index.js # Entry point
|
||||
agent.js # RAG agent logic
|
||||
vectorStore.js # ChromaDB wrapper
|
||||
search.js # Web search helper
|
||||
utils.js # Embedding helper
|
||||
tests/
|
||||
vectorStore.test.js
|
||||
agent.test.js
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- The project **does not** use Qdrant. All references to Qdrant have been removed.
|
||||
- Only ChromaDB is used for vector storage.
|
||||
- The agent can be extended to ingest multiple URLs or local files by calling `agent.ingestFromUrl(url)`.
|
||||
- The embedding function in `utils.js` is a deterministic placeholder. Replace it with a real embedding model (e.g., OpenAI embeddings) for production use.
|
||||
- The agent currently returns concatenated context as the answer. Integrate a language model for richer responses.
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
---
|
||||
Feel free to contribute or open issues for enhancements.
|
||||
MIT License
|
||||
Reference in New Issue
Block a user