File size: 2,628 Bytes
9d70c37
 
 
 
 
 
 
 
 
 
 
 
 
736560d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: AssistantBot
emoji: 😻
colorFrom: red
colorTo: pink
sdk: gradio
sdk_version: 6.14.0
python_version: '3.13'
app_file: app.py
pinned: false
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference


# Ask Julia: AI Assistant

A lightweight, CPU-optimized Retrieval-Augmented Generation (RAG) assistant designed specifically for the `diffusion.fyi` knowledge base.

This project allows users to ask complex questions about flow matching, diffusion models, and custom research notes (like the "Julia Constant"), receiving accurate, mathematically formatted answers in real-time.

## Key Features

*   **CPU-Optimized Inference:** Powered by the `Qwen-2.5-1.5B-Instruct-GGUF` model via `llama-cpp-python`. It is heavily optimized to run on standard CPUs (like a free Hugging Face Space) without needing an expensive GPU.
*   **Custom Knowledge Retrieval (RAG):** Uses a local FAISS vector database to read and retrieve specific context from the `knowledge_base` directory before answering.
*   **Native Math Rendering:** The frontend fully supports LaTeX. Inline math (`$x$`) and block equations (`$$y=x$$`) are parsed and beautifully rendered using MathJax.
*   **Responsive UI:** Features a sleek, mobile-friendly slide-out sidebar that doesn't obstruct the reading material.
*   **Strict Hallucination Control:** The system prompt is engineered with strict low-temperature (`0.1`) constraints to ensure the bot *only* answers based on the provided notes and refuses to guess unknown concepts.

## Tech Stack

*   **Backend:** FastAPI, Python 3.11
*   **AI/LLM:** `llama-cpp-python`, Hugging Face Hub (`Qwen/Qwen2.5-1.5B-Instruct-GGUF`)
*   **RAG Engine:** FAISS (CPU), `sentence-transformers` (`BAAI/bge-small-en-v1.5`)
*   **Frontend:** Vanilla HTML, CSS (Flexbox), JavaScript, MathJax, Marked.js
*   **Deployment:** Docker (Hugging Face Spaces compatible)

## Repository Structure
```text
β”œβ”€β”€ app.py                 # Main FastAPI application and API routes
β”œβ”€β”€ llm_cpu.py             # LLM initialization and strict prompt formatting logic
β”œβ”€β”€ rag.py                 # Vector DB initialization and context retrieval
β”œβ”€β”€ index.html             # The frontend user interface (UI)
β”œβ”€β”€ Dockerfile             # Custom Dockerfile for non-root CPU cloud deployment
β”œβ”€β”€ requirements.txt       # Python dependencies
└── knowledge_base/        # Markdown files containing the core research notes
    β”œβ”€β”€ faiss_index.bin    # Pre-computed vector embeddings
    └── faiss_metadata...  # Metadata linking vectors to text chunks