Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

MAITRI

A Local Retrieval-Augmented AI Companion for Context-Aware Conversations

MAITRI is a fully local Retrieval-Augmented Generation (RAG) AI companion designed for emotionally intelligent, context-aware conversations while preserving user privacy.

The project combines a local Large Language Model (Qwen), semantic retrieval using ChromaDB, long-term conversational memory, and structured prompt engineering to create an AI assistant capable of maintaining context across conversations without relying on cloud services.

Status: 🚧 Active Development


Features

  • πŸ”’ Fully Offline AI Assistant
  • 🧠 Retrieval-Augmented Generation (RAG)
  • πŸ’¬ Long-Term Conversational Memory
  • πŸ“š Semantic Search using ChromaDB
  • ⚑ Streaming Token Generation
  • πŸš€ GPU Accelerated Embeddings (CUDA)
  • πŸ“– Token-Aware Document Chunking
  • πŸ“ Session Logging using JSONL
  • 🧩 Modular Pipeline Architecture
  • ❀️ Emotion-Aware Prompt Engineering
  • πŸ” Semantic Memory Retrieval
  • πŸ›‘οΈ Crisis Detection & Safety Handling

Architecture

User
 β”‚
 β–Ό
Maitri Chat
 β”‚
 β–Ό
Analyst Prompt
 β”‚
 β–Ό
Retriever
 β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί ChromaDB
 β”‚ β”‚
 β”‚ β–Ό
 β”‚ Relevant Memories
 β”‚
 β–Ό
Context Builder
 β”‚
 β–Ό
Qwen Local LLM
 β”‚
 β–Ό
Streaming Response
 β”‚
 β–Ό
Conversation Logger
 β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β–Ί JSONL History
 β”‚
 └────────► Session Summary
 β”‚
 β–Ό
 Memory Indexer
 β”‚
 β–Ό
 ChromaDB

Project Structure

.
β”œβ”€β”€ builder.py
β”œβ”€β”€ clean_memory.py
β”œβ”€β”€ config.py
β”œβ”€β”€ data
β”œβ”€β”€ embedding
β”‚ β”œβ”€β”€ embedder.py
β”‚ └── model.py
β”œβ”€β”€ history
β”œβ”€β”€ LLM
β”‚ └── llm_engine.py
β”œβ”€β”€ loader.py
β”œβ”€β”€ maitri_chat.py
β”œβ”€β”€ models.py
β”œβ”€β”€ pipeline
β”‚ β”œβ”€β”€ indexing.py
β”‚ β”œβ”€β”€ querying.py
β”‚ └── rag_pipeline.py
β”œβ”€β”€ retrival
β”‚ β”œβ”€β”€ context_builder.py
β”‚ β”œβ”€β”€ router.py
β”‚ └── search_service.py
β”œβ”€β”€ src
β”‚ └── chunker.py
β”œβ”€β”€ system_prompt.py
β”œβ”€β”€ vectordb
β”‚ β”œβ”€β”€ base.py
β”‚ β”œβ”€β”€ chroma_store.py
β”‚ └── retriever.py
└── vector_db
 └── chroma.sqlite3

Technology Stack

Component Technology
Language Python 3.13+
LLM Qwen 2.5 (Ollama)
Vector Database ChromaDB
Embedding Model SentenceTransformers
Chunking tiktoken
Storage JSON / JSONL
Hardware NVIDIA CUDA (optional)

How It Works

  1. User sends a message.
  2. The Analyst prompt classifies the conversation.
  3. Relevant memories are retrieved from ChromaDB.
  4. Context Builder prepares the final prompt.
  5. Qwen generates a streamed response.
  6. Conversation is logged.
  7. Session summaries are periodically indexed into the vector database for future retrieval.

Key Improvements

Streaming Generation

Responses are streamed token-by-token instead of waiting for the entire generation to finish.


Long-Term Memory

Past conversations are summarized, embedded, and stored inside ChromaDB, allowing MAITRI to retrieve relevant memories using semantic similarity.


Token-Aware Chunking

Documents are split according to tokenizer limits instead of arbitrary word counts, improving retrieval quality.


Efficient Logging

Conversation history uses append-only JSONL storage for scalable and efficient logging.


GPU Support

Sentence embeddings automatically utilize CUDA when available.


Current Limitations

  • High inference latency depending on hardware
  • Memory summarization can still be improved
  • Prompt engineering is continuously evolving
  • Multi-user support is not yet implemented
  • No graphical user interface (CLI only)

Future Roadmap

  • Reduce inference latency
  • Hybrid retrieval (BM25 + Vector Search)
  • Memory ranking and decay
  • Function calling
  • Voice interaction
  • Web interface
  • Agentic workflow
  • Multi-modal support
  • Quantized model benchmarking
  • Docker deployment

Running the Project

Clone the repository

git clone https://github.com/<your_username>/<repository>.git
cd <repository>

Create a virtual environment

python -m venv venv

Activate it

Linux

source venv/bin/activate

Install dependencies

pip install -r requirements.txt

Start Ollama

ollama serve

Pull Qwen if necessary

ollama pull qwen2.5:7b

Run the chatbot

python maitri_chat.py

Performance

Current observations

Metric Value
Embedding GPU Accelerated
Memory Search ChromaDB
Response Streaming Yes
Average Latency 3–75 seconds
Offline Support Yes

Motivation

This project was created to explore Retrieval-Augmented Generation, prompt engineering, semantic memory, and local Large Language Models while building an AI companion that prioritizes privacy and contextual understanding.

The primary objective is educational: to gain hands-on experience designing scalable AI systems rather than relying solely on existing frameworks.


License

This project is licensed under the MIT License.


Author

Vicky

Bachelor's Student β€” Artificial Intelligence & Machine Learning

Interested in:

  • Artificial Intelligence
  • Retrieval-Augmented Generation
  • Robotics
  • Computer Vision
  • Deep Learning
  • Large Language Models

⭐ If you found this project interesting, consider giving it a star.

About

Retrieval-augmented generation experiments with embeddings, vector databases, memory, and model orchestration.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /