A lightweight Node.js backend for Retrieval-Augmented Generation (RAG), providing API endpoints for document embedding, storage, and vector search using HuggingFace Transformers and Chroma DB.
- Add Document: Generate and store document embeddings.
- Add Multiple Documents: Bulk document embedding and storage.
- Semantic Query: Query stored documents via semantic similarity.
- Health Check: Quick health status for the API.
- Node.js + Express
- ChromaDB for vector storage
- HuggingFace Transformers for text embedding
- @chroma-core/default-embed for embedding initialization
- Winston & Morgan for logging
- dotenv for environment management
GET /– Returns API status
POST /add-doc– Add a single document- Body:
{ id: string, text: string }
- Body:
POST /add-docs– Add multiple documents- Body:
{ ids: string[], texts: string[] }(arrays must be the same length)
- Body:
POST /query– Query documents- Body:
{ question: string }
- Body:
- Node.js >= 18
- Chroma DB instance (see Chroma docs)
npm installCreate a .env file in the root directory (see .env.example):
PORT=3000
MODEL_CACHE=./.cache
CHROMA_URL=http://localhost:8000
CHROMA_URLshould point to your running Chroma instance.MODEL_CACHEdirectory must exist and be writable.
To run ChromaDB locally as the backend vector database, use the included docker-compose file:
docker-compose up -dThis starts the ChromaDB service on port 8000 and stores its data inside the chroma_db directory (mounted as a Docker volume).
Ensure ChromaDB is running before starting your Node.js server.
- Production:
npm start
- Development (auto-reloads):
npm run dev
Add a document:
curl -X POST http://localhost:3000/docs/add-doc \
-H "Content-Type: application/json" \
-d '{ "id": "doc1", "text": "Hello world" }'src/app.js– Express app setupsrc/index.js– App entry and initializationsrc/routes/– API route handlerssrc/services/– External service layer for embedding and vector DB opssrc/utils/– Utilities and common helperssrc/middlewares/– Express middleware functions
ISC