2.4 KiB
2.4 KiB
FAQ Bot with ChromaDB and moderate-censor
This project implements an FAQ bot that uses ChromaDB for vector storage and retrieval, and moderate-censor as the single MCP-tool for content moderation.
Features
- Vector-based FAQ retrieval using OpenAI embeddings and ChromaDB.
- User input moderation with moderate-censor.
- Simple HTTP API (
/ask) to query the bot.
Prerequisites
- Node.js v18+ (or any LTS version)
- npm
- OpenAI API key (set in
.env) - ChromaDB server running locally (default path:
chromadb)
Setup
-
Clone the repository
git clone <repo-url> cd <repo-directory> -
Install dependencies
npm install -
Create a
.envfileOPENAI_API_KEY=your_openai_api_key PORT=3000 -
Prepare FAQ data
Create a
faq.jsonfile in the project root with the following format:[ { "question": "What is ChromaDB?", "answer": "ChromaDB is a vector database for storing and retrieving embeddings." }, { "question": "How do I use the bot?", "answer": "Send a POST request to /ask with a JSON body containing the 'question' field." } ] -
Ingest FAQ data
npm run ingestThis will read
faq.json, generate embeddings, and store them in ChromaDB. -
Start the bot
npm startThe server will listen on the port specified in
.env(default 3000).
Usage
Send a POST request to /ask:
curl -X POST http://localhost:3000/ask \
-H "Content-Type: application/json" \
-d '{"question":"What is ChromaDB?"}'
Response:
{
"answer": "ChromaDB is a vector database for storing and retrieving embeddings."
}
If the question contains disallowed content, the bot will respond with a 403 status and reasons.
Project Structure
├── package.json
├── src
│ ├── index.js # HTTP server and bot logic
│ ├── ingest.js # FAQ ingestion script
│ └── middleware.js # Moderation middleware
├── faq.json # FAQ data file
└── README.md
Notes
- The bot uses the
text-embedding-ada-002model for embeddings. - Only one MCP-tool (
moderate-censor) is used as required. - Ensure the ChromaDB server is running before ingesting data or starting the bot.
License
MIT License