1.9 KiB
1.9 KiB
RAG Agent with ChromaDB and Web Search
This project implements a Retrieval-Augmented Generation (RAG) agent that uses ChromaDB as the vector database and the OpenAI API to generate responses based on retrieved documents. It also includes a simple web‑search component that fetches content from specified URLs for indexing.
Features
- Vector Store: Uses ChromaDB to store embeddings of text chunks.
- OpenAI Integration: Generates answers using GPT‑3.5‑Turbo.
- Web Search: Fetches and parses HTML pages, splits them into manageable chunks.
- Command Line Interface: Ask questions interactively.
Prerequisites
- Node.js v18+ (supports native ES modules and
node-fetchv2). - An OpenAI API key.
Setup
-
Clone the repository (or copy the files into a directory).
-
Install dependencies
npm install -
Configure environment
Create a
.envfile in the project root (or edit the existing one) and add your OpenAI API key:OPENAI_API_KEY=your_api_key_here -
Run the agent
npm startThe script will:
- Fetch and index the example URLs.
- Prompt you to enter questions.
- Display answers generated by the RAG agent.
Customization
- Adding URLs: Edit the
urlsarray insrc/index.jsto index different web pages. - Chunk Size: Adjust the
sizeparameter inchunkTextinsidesrc/webSearch.jsif you need larger or smaller chunks. - Model Parameters: Modify temperature, max tokens, or model name in
src/agent.js.
Notes
- The implementation strictly uses ChromaDB as the vector database; no other vector DBs are used.
- All dependencies are declared in
package.jsonand can be installed vianpm install. - The OpenAI API key is loaded securely from the
.envfile usingdotenv.
License
MIT License
Enjoy building with RAG!