Skip to content

H0NEYP0T-466/lettaXrag

LettaXRAG - Conversational AI with RAG & Personality

GitHub License GitHub Stars GitHub Forks GitHub Issues GitHub Pull Requests Contributions Welcome
Last Commit Commit Activity Repo Size Code Size
Top Language Languages Count
Documentation Open Source Love

A full-stack conversational AI system featuring Isabella, a sassy AI assistant powered by RAG (Retrieval-Augmented Generation) and comprehensive logging.

⚠️ Security Note: Letta personality engine is disabled by default due to known vulnerabilities. See SECURITY.md for details. Isabella's personality is maintained through LLM system prompts.

🌟 Features

  • 🎭 Personality: Isabella - your sassy, confident AI assistant with attitude
  • πŸ“š RAG System: FAISS-based document retrieval for knowledge-enhanced responses
  • πŸ’¬ Real-time Chat: Terminal-style chat interface with monospace fonts
  • 🎨 Rich Rendering: Full support for Markdown, LaTeX, code syntax highlighting, and tables
  • πŸ“ Document Upload: Support for .txt, .md, .pdf, and .docx files (backend API)
  • πŸ” Rich Logging: Comprehensive colored console logs tracking every step
  • πŸ’Ύ MongoDB Storage: Persistent conversation history
  • πŸ”’ Security: Updated dependencies with patched vulnerabilities
  • πŸ“– Letta Integration: Optional personality engine (see LETTA_INFO.md)

ℹ️ Learn about Letta: For detailed information about Letta personality engine, how it works, and implementation details, see LETTA_INFO.md

πŸ—οΈ Architecture

Backend (Python FastAPI)

  • FastAPI with async support (v0.109.1+ - patched)
  • MongoDB for data persistence
  • FAISS-CPU for vector similarity search
  • Sentence-transformers for embeddings
  • Letta for personality management (optional - see LETTA_INFO.md)
  • LongCat LLM API integration
  • Rich library for beautiful console logging

Frontend (React + TypeScript)

  • Modern React 19 with TypeScript
  • Zustand for state management
  • Axios for API communication
  • Terminal-style UI with monospace fonts
  • React-Markdown for Markdown rendering
  • KaTeX for LaTeX math rendering
  • React-Syntax-Highlighter for code blocks
  • Full table rendering support

πŸ› οΈ Tech Stack & Dependencies

Backend Stack

Python FastAPI MongoDB Motor
FAISS Sentence Transformers PyPDF2 Python-docx
Rich Watchdog Letta LongCat LLM

Frontend Stack

React TypeScript Vite Node.js
Zustand Axios React Markdown KaTeX
Rehype Remark Syntax Highlighter

Dependencies

Backend – Full list with exact versions & security patches in backend/requirements.txt
Frontend – Full list with exact versions in package.json

All dependencies are kept up-to-date with patched vulnerabilities (see SECURITY.md).

πŸ“‹ Prerequisites

  • Node.js 20+ and npm
  • Python 3.9+
  • MongoDB (local or remote)
  • LongCat API Key (Get one here)

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/H0NEYP0T-466/lettaXrag.git
cd lettaXrag

2. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
cp .env.example .env

# Edit .env and add your API keys
nano .env  # or use your favorite editor

Required Environment Variables (.env):

MONGODB_URI=mongodb://localhost:27017/lettaXrag
LONGCAT_API_KEY=your_actual_api_key_here

# Letta - Local Server (Recommended)
LETTA_BASE_URL=http://localhost:8283
# No LETTA_API_KEY needed for local server

# Letta - Cloud Server (Alternative)
# LETTA_BASE_URL=https://api.letta.com
# LETTA_API_KEY=your_letta_cloud_api_key_here

# Optional
DATA_FOLDER=./data
FAISS_INDEX_PATH=./storage/faiss_index.bin
LOG_LEVEL=DEBUG

πŸ“– Letta Local Server Setup: If you want to use Letta personality engine with a local server, see backend/letta.txt for detailed setup instructions including PostgreSQL configuration and troubleshooting.

3. Frontend Setup

# From root directory
npm install

# Create .env file
cp .env.example .env

# Edit if needed (default: http://localhost:8000)

4. Add Documents (Optional)

Add your knowledge base documents to the backend/data folder:

cd backend/data
# Add your .txt, .md, .pdf, or .docx files here

The system will automatically index them on startup!

5. Start the Application

Terminal 1 - Backend:

cd backend
source venv/bin/activate  # On Windows: venv\Scripts\activate
python main.py

The backend will start on http://localhost:8000

Terminal 2 - Frontend:

npm run dev

The frontend will start on http://localhost:5173

🎯 Usage

Chat with Isabella

  1. Open your browser to http://localhost:5173
  2. Type your question in the terminal-style input box
  3. Press Enter or click [send]
  4. Isabella will respond using her personality and knowledge base!

Terminal-Style Interface

The chat interface features:

  • Black background with green and cyan text (terminal aesthetic)
  • Monospace font (Courier New) throughout
  • Minimal design - no gradients, just clean text
  • Rich content rendering:
    • Markdown formatting (headers, lists, bold, italic, links)
    • LaTeX math equations (inline: $...$ and display: $$...$$)
    • Code blocks with syntax highlighting
    • Tables with proper formatting
    • Blockquotes and other Markdown features

Upload Documents

Documents can be uploaded via the API endpoint:

curl -X POST http://localhost:8000/api/upload \
  -F "file=@/path/to/document.pdf"

The system will automatically re-index and Isabella can use this knowledge!

View Sources

When Isabella uses documents to answer your question:

  • Click "πŸ“š Show Sources" on her message
  • See which documents she referenced

πŸ”Œ API Endpoints

POST /api/chat

Send a message to Isabella

Request:

{
  "message": "What is RAG?",
  "session_id": "optional-session-id"
}

Response:

{
  "response": "RAG stands for...",
  "rag_sources": ["document1.pdf", "notes.md"],
  "timestamp": "2026-01-20T12:00:00"
}

GET /api/health

Check system health status

POST /api/upload

Upload a new document for indexing

GET /api/stats

Get system statistics (message count, indexed documents)

πŸ“Š System Flow

  1. User sends message β†’ Frontend
  2. Frontend POST to /api/chat β†’ Backend
  3. Backend logs user prompt with Rich
  4. Letta processes message (adds personality)
  5. RAG retrieves relevant context from FAISS
  6. Constructs final prompt with context
  7. Sends to LongCat LLM API
  8. Logs LLM response
  9. Saves to MongoDB
  10. Returns to frontend
  11. Frontend displays Isabella's response

🎨 Customization

Change Isabella's Personality

For Letta-based personality, edit backend/services/letta_service.py:

self.persona = """Your custom personality here..."""

For LLM-based personality (when Letta is disabled), edit backend/services/llm_service.py:

system_prompt = """Your custom personality..."""

See LETTA_INFO.md for detailed information about personality management.

Adjust RAG Settings

Edit backend/services/rag_service.py:

def retrieve_context(self, query: str, k: int = 5):  # Change k value
    # Adjust chunk_size and overlap in _chunk_text()

Modify LLM Settings

Edit backend/services/llm_service.py:

temperature=0.7,  # Adjust creativity (0.0-1.0)
max_tokens=1000,  # Adjust response length

πŸ“ Project Structure

lettaXrag/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                 # FastAPI entry point
β”‚   β”œβ”€β”€ config.py              # Configuration
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── schemas.py         # Pydantic models
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ db_service.py      # MongoDB operations
β”‚   β”‚   β”œβ”€β”€ rag_service.py     # FAISS RAG system
β”‚   β”‚   β”œβ”€β”€ letta_service.py   # Personality engine
β”‚   β”‚   └── llm_service.py     # LongCat integration
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── chat.py            # API endpoints
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ logger.py          # Rich logging
β”‚   β”‚   └── file_watcher.py    # Data folder monitor
β”‚   β”œβ”€β”€ data/                  # Your documents
β”‚   └── storage/               # FAISS index storage
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ services/              # API client
β”‚   β”œβ”€β”€ hooks/                 # Custom React hooks
β”‚   β”œβ”€β”€ store/                 # Zustand store
β”‚   └── types/                 # TypeScript types
└── package.json

πŸ› Troubleshooting

MongoDB Connection Error

# Make sure MongoDB is running
sudo systemctl start mongodb  # Linux
brew services start mongodb-community  # macOS

FAISS Index Issues

# Delete and rebuild index
rm backend/storage/*
# Restart backend - it will rebuild automatically

Letta Initialization Fails

The system will continue without Letta if initialization fails. Isabella will still work but without personality processing.

Common causes:

  • Letta server not running (if using local server)
  • Wrong LETTA_BASE_URL configuration
  • PostgreSQL not running (if Letta is configured to use it)

Solutions:

  • See backend/letta.txt for comprehensive Letta setup guide
  • Check your .env file has: LETTA_BASE_URL=http://localhost:8283
  • Make sure Letta server is running: letta server
  • Or disable Letta by commenting out LETTA_BASE_URL in .env

Port Already in Use

# Change backend port in main.py
uvicorn.run("main:app", host="0.0.0.0", port=8001)

# Update frontend .env
VITE_API_URL=http://localhost:8001

πŸ”’ Security Notes

⚠️ Important: Please review SECURITY.md for comprehensive security information.

Quick Security Checklist

  • βœ… Dependencies Updated: All known vulnerabilities patched
  • ⚠️ Letta Disabled: Library has unpatched vulnerabilities (see SECURITY.md)
  • πŸ”’ Environment Variables: Never commit your .env file
  • πŸ”‘ API Keys: Keep your API keys secure and rotate regularly
  • 🌐 CORS: Use environment-specific CORS settings in production
  • πŸ“ File Uploads: Implement size limits and validation in production
  • πŸ” Authentication: Add user authentication before production deployment
  • πŸ›‘οΈ Rate Limiting: Implement rate limiting for production use

For Production Deployment: See the production security checklist in SECURITY.md

πŸ“ License

MIT License - feel free to use this project as you wish!

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“§ Support

For issues and questions, please open an issue on GitHub.


Made with πŸ’… by the LettaXRAG Team

About

πŸ€– Full-stack conversational AI using a Letta (MemGPT) + RAG hybrid architecture for long-term memory, context persistence, and grounded responses. Built with FastAPI, React, FAISS, and MongoDB, featuring Isabella β€” a personality-driven assistant with document ingestion, structured memory, logging, and a terminal-style streaming chat UI.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors