Skip to content

A custom chatbot built with NestJS, MongoDB, PostgreSQL with pgvector extension for vector similarity search

Notifications You must be signed in to change notification settings

AJOYSR/Custom-Chatbot

Repository files navigation

NestJS Chatbot with pgvector

A custom chatbot built with NestJS, MongoDB, PostgreSQL with pgvector extension for vector similarity search.

Demo

image

Prerequisites

  • Node.js (>= v16)
  • MongoDB
  • PostgreSQL (with pgvector extension)
  • Ollama (for text embeddings)

Environment Setup

  1. Clone the repository
  2. Copy .env.example to .env and update the following variables:
# Application
PORT=
NODE_ENV=

# PostgreSQL
POSTGRES_HOST=
POSTGRES_PORT=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DATABASE=
DB_SCHEMA=

# MongoDB
MONGODB_URI=your_mongodb_connection_string

Project Overview

This README provides:

  1. Clear setup instructions
  2. Environment configuration
  3. Database setup requirements
  4. Available API endpoints
  5. Project structure
  6. Testing instructions

Feel free to customize this README further based on any specific requirements or additional features of your project.

Database Setup

PostgreSQL Vector Database Setup

1. Create Database

CREATE DATABASE vectordb;

2. Enable Required Extensions

-- Enable vector extension for embedding operations
CREATE EXTENSION IF NOT EXISTS vector;

-- Enable pg_trgm extension for text similarity operations
CREATE EXTENSION IF NOT EXISTS pg_trgm;

3. Create Table

CREATE TABLE question_n_answers (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    question TEXT NOT NULL,
    answer TEXT NOT NULL,
    "botId" TEXT NOT NULL,
    embedding vector(768) NOT NULL,
    "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

Table Structure

  • id: UUID (Primary Key, auto-generated)
  • question: TEXT (NOT NULL)
  • answer: TEXT (NOT NULL)
  • botId: TEXT (NOT NULL)
  • embedding: vector(768) (NOT NULL)
  • createdAt: TIMESTAMP WITH TIME ZONE (default: CURRENT_TIMESTAMP)
  • updatedAt: TIMESTAMP WITH TIME ZONE (default: CURRENT_TIMESTAMP)

Notes

  • The table uses the pgvector extension for vector operations
  • The pg_trgm extension is required for text similarity operations
  • Vector dimension is set to 768
  • Timestamps are automatically managed
  • Primary key is auto-generated using gen_random_uuid()

About

A custom chatbot built with NestJS, MongoDB, PostgreSQL with pgvector extension for vector similarity search

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published