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 OpenAIs GPT models.

Features

  • Vector Store Uses ChromaDB for storing and querying embeddings.
  • Embeddings Generated with OpenAIs text-embedding-ada-002.
  • Chat Generates responses with OpenAIs 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

    git clone https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu.git
    cd agent-s-rag-pamyatyu
    
  2. Install dependencies

    npm install
    
  3. Configure environment variables

    Create a .env file in the project root (or export the variables in your shell):

    # 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:

    docker run -d -p 8000:8000 chromadb/chroma
    

Usage

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:

npm test

All tests should pass after the ChromaDB integration.

Notes

  • The agents 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!

S
Description
BroJS: Агент с RAG-памятью
Readme 145 KiB
Languages
Python 67.1%
TypeScript 16.6%
JavaScript 15.4%
Dockerfile 0.9%