Skip to content

Latest commit

 

History

History
136 lines (101 loc) · 3.18 KB

File metadata and controls

136 lines (101 loc) · 3.18 KB

RAG (Retrieval-Augmented Generation) Setup Guide

This guide explains how to set up and use the RAG system in your note-taking app.

Overview

RAG enhances AI responses by automatically searching your notes for relevant context. When enabled, the AI will:

  • Search through your notes to find relevant information
  • Include citations with links to source notes
  • Provide more accurate answers about your content

Prerequisites

1. PostgreSQL with pgvector

First, install PostgreSQL and the pgvector extension:

macOS:

brew install postgresql
brew install pgvector
brew services start postgresql

Ubuntu/Debian:

sudo apt update
sudo apt install postgresql postgresql-contrib
sudo apt install postgresql-15-pgvector

2. Ollama for Embeddings

Install Ollama for local embedding generation:

# Download from https://ollama.ai
# Then pull the embedding model:
ollama pull embeddinggemma

Quick Setup

  1. Run the setup script:

    cd scripts
    ./setup_postgres.sh
  2. Configure environment variables:

    The script creates a .env file. Update it if needed:

    POSTGRES_HOST=localhost
    POSTGRES_PORT=5432
    POSTGRES_DB=noteraity_vectors
    POSTGRES_USER=postgres
    POSTGRES_PASSWORD=postgres
    
    OLLAMA_HOST=http://localhost:11434
    OLLAMA_EMBEDDING_MODEL=embeddinggemma
  3. Start the app:

    npm run dev

Using RAG

Enable RAG in Settings

  1. Open Settings → AI Configuration
  2. Find the "RAG (Retrieval-Augmented Generation)" section
  3. Click the toggle to enable RAG

Index Your Notes

When you first enable RAG, you need to index your existing notes:

  1. In the Tauri dev console, you can manually trigger indexing
  2. New notes are automatically indexed when created/updated

Chat with RAG

When RAG is enabled:

  • Your questions will automatically search through your notes
  • Responses will include numbered citations [1], [2], etc.
  • Click on citations to navigate to the source note
  • Hover over citations to see relevance scores

Features

Citations

  • Each citation shows:
    • Note title
    • Preview of relevant content
    • Relevance score (0-100%)
    • Click to navigate to the note

Search Quality

  • Uses semantic search (understands meaning, not just keywords)
  • Finds related concepts even with different wording
  • Ranks results by relevance

Troubleshooting

PostgreSQL Connection Issues

# Check if PostgreSQL is running
pg_isready

# Check pgvector installation
psql -d noteraity_vectors -c "CREATE EXTENSION IF NOT EXISTS vector;"

Ollama Issues

# Check if Ollama is running
curl http://localhost:11434/api/tags

# Check if embedding model is installed
ollama list | grep embeddinggemma

RAG Not Working

  1. Check the browser console for errors
  2. Ensure PostgreSQL is running
  3. Ensure Ollama is running
  4. Try re-indexing your notes

Technical Details

  • Chunking: Notes are split into ~512 token chunks with 128 token overlap
  • Embeddings: Vectors generated using embeddinggemma
  • Storage: PostgreSQL with pgvector for efficient similarity search
  • Retrieval: Top 5 most relevant chunks with >30% similarity threshold