95 lines
2.5 KiB
Markdown
95 lines
2.5 KiB
Markdown
# Agent with RAG Memory (ChromaDB)
|
||
|
||
This project implements a Retrieval-Augmented Generation (RAG) agent that uses **ChromaDB** as its sole vector store. The agent can ingest documents, store their embeddings, retrieve relevant passages, and generate answers using OpenAI’s GPT models.
|
||
|
||
## Features
|
||
|
||
- **Vector Store** – Uses ChromaDB for storing and querying embeddings.
|
||
- **Embeddings** – Generated with OpenAI’s `text-embedding-ada-002`.
|
||
- **Chat** – Generates responses with OpenAI’s `gpt-3.5-turbo`.
|
||
- **Public API** – The `Agent` class exposes `init`, `ingest`, and `ask` methods, keeping the original interface unchanged.
|
||
|
||
## Setup
|
||
|
||
1. **Clone the repository**
|
||
|
||
```bash
|
||
git clone https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu.git
|
||
cd agent-s-rag-pamyatyu
|
||
```
|
||
|
||
2. **Install dependencies**
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
3. **Configure environment variables**
|
||
|
||
Create a `.env` file in the project root (or export the variables in your shell):
|
||
|
||
```dotenv
|
||
# ChromaDB
|
||
CHROMA_URL=localhost
|
||
CHROMA_PORT=8000
|
||
|
||
# OpenAI
|
||
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
|
||
```
|
||
|
||
- `CHROMA_URL` and `CHROMA_PORT` point to your ChromaDB instance.
|
||
- `OPENAI_API_KEY` is required for embeddings and chat completions.
|
||
|
||
4. **Run ChromaDB**
|
||
|
||
Ensure a ChromaDB server is running on the specified host/port. You can start a local instance with Docker:
|
||
|
||
```bash
|
||
docker run -d -p 8000:8000 chromadb/chroma
|
||
```
|
||
|
||
## Usage
|
||
|
||
```js
|
||
const { Agent } = require('./src');
|
||
|
||
(async () => {
|
||
const agent = new Agent();
|
||
await agent.init();
|
||
|
||
// Ingest documents
|
||
await agent.ingest('The quick brown fox jumps over the lazy dog.', { source: 'example.txt' });
|
||
|
||
// Ask a question
|
||
const answer = await agent.ask('What did the fox do?');
|
||
console.log(answer);
|
||
})();
|
||
```
|
||
|
||
## API
|
||
|
||
| Method | Description |
|
||
|--------|-------------|
|
||
| `init()` | Initializes the vector store (creates collection if needed). |
|
||
| `ingest(text, metadata)` | Adds a document to the vector store. |
|
||
| `ask(question)` | Retrieves relevant passages and generates an answer. |
|
||
|
||
## Testing
|
||
|
||
If you have a test suite, run:
|
||
|
||
```bash
|
||
npm test
|
||
```
|
||
|
||
All tests should pass after the ChromaDB integration.
|
||
|
||
## Notes
|
||
|
||
- The agent’s public API remains unchanged; only the underlying vector store implementation has been swapped to ChromaDB.
|
||
- No new external services are introduced beyond ChromaDB and the existing OpenAI usage.
|
||
- Ensure that the ChromaDB server is reachable; otherwise, the agent will throw connection errors.
|
||
|
||
---
|
||
|
||
Happy coding! |