Files
agent-s-rag-pamyatyu/README.md
T
2026-06-24 14:28:11 +03:00

2.6 KiB
Raw Blame History

RAG Memory Agent

A simple Retrieval-Augmented Generation (RAG) memory system built with Node.js, TypeScript, and Express.
It stores user data in an inmemory virtual file system and uses a language model (OpenAI or a mock) to answer queries based on stored memory.

Features

  • Virtual File System CRUD operations for memory entries.
  • LLM abstraction Uses OpenAI GPT3.5Turbo if OPENAI_API_KEY is set, otherwise falls back to a mock echo.
  • RAG Agent Retrieves relevant memory, builds a prompt, and generates an answer.
  • RESTful API Endpoints for managing memory and querying the agent.
  • Unit tests Jest tests for VFS and Agent logic.

Installation

git clone https://git.brojs.ru/kuzakhmetovartur/prakticheskoe-zadanie-agent-s-rag-pamyat.git
cd prakticheskoe-zadanie-agent-s-rag-pamyat
npm install

Environment Variables

Create a .env file based on .env.example:

cp .env.example .env
  • OPENAI_API_KEY (optional) Your OpenAI API key. If omitted, the agent will use a mock LLM.
  • PORT Port number for the server (default: 3000).

Running the Server

npm run dev   # Development with ts-node
# or
npm run build
npm start

The server will start on http://localhost:<PORT>.

API Endpoints

Method Path Description Body (JSON)
GET /memory List all memory entries (id, snippet).
POST /memory Create a new memory entry. { "content": "string" }
DELETE /memory/:id Delete a memory entry by ID.
POST /query Query the agent. { "query": "string" }

Example Requests

# Add memory
curl -X POST http://localhost:3000/memory \
  -H "Content-Type: application/json" \
  -d '{"content":"I love programming in TypeScript."}'

# Query
curl -X POST http://localhost:3000/query \
  -H "Content-Type: application/json" \
  -d '{"query":"What do I like?"}'

Testing

Run unit tests with coverage:

npm test

Project Structure

src/
  index.ts          # Server entry point
  agent.ts          # RAG agent logic
  llm.ts            # LLM abstraction
  vfs.ts            # Virtual file system
  utils.ts          # Helpers
  routes.ts         # Express routes
  middleware.ts     # Error handling & validation
  tests/
    vfs.test.ts
    agent.test.ts

License

MIT © Your Name