Skip to content
siddharth-57Public

About

A GenAI-powered Retrieval-Augmented Generation (RAG) system developed in Python that transforms unstructured documents into a searchable knowledge base using Qdrant for vector search and PostgreSQL for metadata management, integrating Large Language Models (LLMs) to generate contextually relevant responses to natural language queries.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

QueryMind

QueryMind is an AI-powered Retrieval-Augmented Generation (RAG) application that enables users to query unstructured data using natural language. The system ingests documents, generates vector embeddings, stores them in Qdrant, enhances user queries for improved retrieval, retrieves semantically relevant information, and uses a configurable Large Language Model (LLM) to generate accurate, context-aware responses.


Features

  • Document ingestion pipeline
  • Automatic text preprocessing and chunking
  • Embedding generation
  • Vector similarity search using Qdrant
  • Query enhancement for improved retrieval
  • Retrieval-Augmented Generation (RAG)
  • Natural language question answering
  • Metadata storage and retrieval
  • Configurable embedding providers
  • Configurable LLM providers
  • Modular provider architecture
  • Dockerized deployment

Tech Stack

Backend

  • Python
  • SQLAlchemy
  • Alembic

Database

  • PostgreSQL
  • Qdrant (Vector Database)

AI/ML

  • Ollama
  • OpenAI
  • Anthropic
  • Gemini
  • Voyage AI
  • Embedding Models
  • Retrieval-Augmented Generation (RAG)

Infrastructure

  • Docker
  • Docker Compose

Project Architecture

                Documents
                    │
                    ▼
          Document Ingestion
                    │
                    ▼
          Text Preprocessing
                    │
                    ▼
             Text Chunking
                    │
                    ▼
         Embedding Generation
                    │
                    ▼
        Embedding Provider
        ┌──────────┼──────────┐
        │          │          │
      Ollama     OpenAI     Voyage
        │          │          │
        └──────────┼──────────┘
                   │
                   ▼
      Qdrant Vector Database
                   │
                   │
             User Question
                   │
                   ▼
          Query Enhancement
                   │
                   ▼
         Multiple Search Queries
                   │
                   ▼
         Embedding Generation
                   │
                   ▼
       Vector Similarity Search
                   │
                   ▼
          Retrieved Context
                   │
                   ▼
            Prompt Builder
                   │
                   ▼
             LLM Service
                   │
                   ▼
             LLM Provider
        ┌──────────┼──────────┬──────────┐
        │          │          │          │
      Ollama     OpenAI   Anthropic   Gemini
        │          │          │          │
        └──────────┼──────────┼──────────┘
                   │
                   ▼
          Natural Language Answer

How It Works

1. Document Ingestion

Documents are read and processed before being stored.


2. Text Preprocessing and Chunking

Large documents are processed and divided into smaller chunks suitable for embedding generation and semantic retrieval.


3. Embedding Generation

Each chunk is converted into a dense vector representation using the configured embedding provider.

QueryMind supports multiple embedding providers:

  • Ollama
  • OpenAI
  • Voyage AI

The active provider and model are configured through environment variables.


4. Vector Storage

Embeddings are stored inside Qdrant along with the original document chunks and associated metadata.


5. Query Enhancement

When a user asks a question, the query is first passed through the query enhancement component.

The LLM generates search-oriented queries that can improve semantic retrieval.


6. Semantic Retrieval

Each generated search query is converted into an embedding.

The embeddings are used to perform similarity searches against Qdrant.

The retrieved results are combined and duplicate contexts are removed before being passed to the LLM.


7. Prompt Construction

The original user question and the retrieved context are combined using the Prompt Builder to construct the final prompt.


8. Response Generation

The final prompt is passed to the configured LLM through the LLM Service.

QueryMind supports multiple LLM providers:

  • Ollama
  • OpenAI
  • Anthropic
  • Gemini

The provider is selected through environment variables, allowing the underlying LLM to be changed without modifying the RAG pipeline.


Example Workflow

User Question

        │

        ▼

Query Enhancement

        │

        ▼

Generate Search Queries

        │

        ▼

Generate Query Embeddings

        │

        ▼

Qdrant Similarity Search

        │

        ▼

Retrieve Relevant Chunks

        │

        ▼

Remove Duplicate Context

        │

        ▼

Build Prompt

        │

        ▼

Send Prompt to LLM

        │

        ▼

Generate Answer

        │

        ▼

Return Response

Future Improvements

  • Hybrid Search (Vector + Keyword)
  • Multi-document retrieval
  • Streaming responses
  • Conversation memory
  • User authentication
  • Web interface
  • Knowledge graph integration
  • API endpoints for external applications
  • Retrieval and answer evaluation
  • RAG quality and performance monitoring

Project Setup

Prerequisites

  • These instructions assume you already have Docker, Git, and Python installed on your host.
  • Ollama is required if you are using Ollama as an LLM or embedding provider.

1. Clone the Repository

git clone https://github.com/siddharth-57/QueryMind.git

cd QueryMind

2. Create and Activate a Virtual Environment

Create a virtual environment using Python 3.11:

python3.11 -m venv venv

Activate the virtual environment:

source venv/bin/activate

3. Install Project Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Copy the example environment file:

cp .env.example .env

Configure the .env file with the required provider, model, database, and API key settings.

Example:

#################################################
# Embedding Configuration
#################################################

EMBEDDING_PROVIDER=ollama
EMBEDDING_MODEL=qwen3-embedding:4b
EMBEDDING_DIMENSION=2560


#################################################
# LLM Configuration
#################################################

LLM_PROVIDER=ollama
LLM_MODEL=qwen3:8b


#################################################
# API Keys
#################################################

OPENAI_API_KEY=
ANTHROPIC_API_KEY=
GOOGLE_API_KEY=
VOYAGE_API_KEY=

API keys are only required when using the corresponding provider.


5. Setup Ollama

Use Ollama to run open-source models locally on your host.

Install Ollama

brew install ollama

Start the Ollama Server

ollama serve

Note: Keep this terminal window open when using Ollama providers.

Download Required Models

Pull the embedding model:

ollama pull qwen3-embedding:4b

Pull the LLM model:

ollama pull qwen3:8b

Note: You can replace these model names with other models available on Ollama by updating the corresponding values in .env.


6. Start Docker Containers

docker compose up -d

7. Enable the pgvector Extension

Connect to the PostgreSQL database:

docker exec -it QueryMind-postgres psql -U postgres -d QueryMind

Inside PostgreSQL, enable the extension:

CREATE EXTENSION IF NOT EXISTS vector;

To verify that the extension has been enabled:

\dx

Although the pgvector image includes the extension binaries, PostgreSQL still requires you to enable the extension once per database using CREATE EXTENSION.


8. Run Database Migrations

Generate the migration:

alembic revision --autogenerate -m "create tables"

Apply the migration:

alembic upgrade head

Running the Project

Run the following scripts in order from the QueryMind project root.

1. Synchronize Emails

python3 -m scripts.test_sync_service

2. Run the Preprocessing Pipeline

python3 -m scripts.test_preprocessing_pipeline

3. Test the Qdrant Connection

python3 -m scripts.test_qdrant

4. Index the Document Chunks

python3 -m scripts.index_chunks

5. Test Semantic Search

python3 -m scripts.test_search

6. Test the LLM

python3 -m scripts.test_llm

7. Test Prompt Builder

python3 -m scripts.test_prompt_builder

8. Test Retrieval

python3 -m scripts.test_retrieval

About

A GenAI-powered Retrieval-Augmented Generation (RAG) system developed in Python that transforms unstructured documents into a searchable knowledge base using Qdrant for vector search and PostgreSQL for metadata management, integrating Large Language Models (LLMs) to generate contextually relevant responses to natural language queries.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages