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

  1. Clone the repository

    git clone <repo-url>
    cd <repo-directory>
    
  2. Install dependencies

    npm install
    
  3. Create a .env file

    OPENAI_API_KEY=your_openai_api_key
    PORT=3000
    
  4. Prepare FAQ data

    Create a faq.json file 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."
      }
    ]
    
  5. Ingest FAQ data

    npm run ingest
    

    This will read faq.json, generate embeddings, and store them in ChromaDB.

  6. Start the bot

    npm start
    

    The 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-002 model 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

S
Description
BroJS: Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool
Readme 142 KiB
Languages
Python 100%