RAG Pipeline

Localmind keeps the document flow local-first. Upload creates durable local metadata first, stores the original file under the document id, queues ingestion, and only then later parsing/chunking/embedding workers make semantic search available.

Upload slice

sequenceDiagram
    actor User
    participant UI as "Tauri React UI"
    participant API as "LocalApi"
    participant Handler as "UploadDocumentHandler"
    participant Buckets as "BucketResolver"
    participant Storage as "LocalFileStorageService"
    participant DB as "SQLite"

    User->>UI: Upload document
    UI->>API: POST /api/v1/documents/upload
    API->>Handler: UploadDocumentCommand
    Handler->>Handler: Validate file size/name/extension
    Handler->>Buckets: Resolve bucket
    Buckets->>DB: Read requested or last selected bucket
    alt No bucket available
        Buckets->>DB: Create Default bucket
    end
    Buckets-->>Handler: Bucket
    Handler->>Storage: Save runtime/app/files/{documentId}/{fileName}
    Storage-->>Handler: StoredFileDto + SHA-256
    Handler->>DB: Add Document + DocumentFile
    Handler->>DB: SaveChanges
    Handler->>DB: Create Pending IngestionJob
    Handler-->>API: UploadDocumentResponse
    API-->>UI: 201 Created

Rules:

  • Document.BucketId is always assigned for new uploads.
  • Explicit missing bucketId is an error.
  • Missing optional bucketId resolves to the last selected bucket, then to the system Default bucket.
  • Files are stored predictably in runtime/app/files/{documentId}/{originalFileName}.

Full RAG flow

flowchart LR
    Upload["Upload document"] --> ResolveBucket["Resolve bucket"]
    ResolveBucket --> SaveFile["Save original file"]
    SaveFile --> Job["Create ingestion job"]
    Job --> Extract["Extract text"]
    Extract --> Chunk["Split into chunks"]
    Chunk --> Embed["Generate embeddings locally"]
    Embed --> Store["Store chunks, vectors, and FTS rows"]
    Store --> SearchReady["Hybrid search ready"]

    Question["User question"] --> EmbedQuestion["Embed question locally"]
    Question --> KeywordSearch["SQLite FTS/BM25 search"]
    EmbedQuestion --> VectorSearch["Vector search"]
    VectorSearch --> Fusion["Reciprocal Rank Fusion"]
    KeywordSearch --> Fusion
    Fusion --> Context["Build RAG context with guardrails"]
    Context --> Chat["Call local chat model"]
    Chat --> Answer["Answer with sources"]

Semantic search and RAG retrieval use hybrid ranking. The existing local vector search finds semantically similar chunks, SQLite FTS/BM25 finds exact keyword matches, and Reciprocal Rank Fusion returns one ranked source list. RAG context construction keeps top hybrid candidates only when they have a strong vector score or enough specific keyword overlap to avoid passing broad keyword matches into chat context.

Ingestion Lifecycle

This page keeps the ingestion flow diagram close to the RAG pipeline. Full lifecycle rules, retry/cancel behavior, progress semantics, document status updates, and diagnostics fields are documented in Document ingestion.

sequenceDiagram
    participant Processor as "IngestionJobProcessor"
    participant Repo as "IIngestionJobRepository"
    participant DB as "SQLite"
    participant Extractor as "DocumentTextExtractor"
    participant Chunker as "DocumentChunker"

    Processor->>Repo: Claim Pending job
    Repo->>DB: Pending -> Processing, progress 10
    Processor->>DB: Load Document + DocumentFile
    Processor->>DB: Mark document Processing
    Processor->>Repo: Processing, "Extracting text", progress 30
    Processor->>Extractor: Extract text from local file
    alt Supported text/markdown/html/pdf/docx/pptx
        Extractor-->>Processor: Text segments with source metadata
        Processor->>Repo: Chunking, progress 50
        Processor->>Chunker: Split into chunks
        Chunker-->>Processor: Chunk texts
        Processor->>Repo: Embedding, progress 75
        Processor->>DB: Replace DocumentChunk rows with page/slide metadata where available
        Processor->>DB: Sync SQLite FTS rows for the document
        Processor->>Repo: Indexed, progress 100
        Processor->>DB: Mark document Indexed
    else Corrupt or unsupported file
        Extractor-->>Processor: Extraction exception
        Processor->>Repo: Failed with ErrorCode + sanitized ErrorMessage
        Processor->>DB: Mark document Failed
    end

Public ingestion statuses are Pending, Processing, Chunking, Embedding, Indexed, Failed, and Cancelled. Cancellation is supported for pending/active jobs, and retry is supported for failed/cancelled jobs.

Chat Title Lifecycle

Chat conversations start with a default title of New chat. After the first user message is sent, the frontend can call POST /api/v1/chats/{id}/generate-title to request an AI-generated title derived from the opening message.

Rules:

  • Title generation is a separate, optional call — it is not part of the SSE answer stream.
  • The backend sets TitleGeneratedAt on the Conversation entity when a title is generated.
  • If the user manually renames the chat, TitleEditedAt is set.
  • A conversation with TitleEditedAt set is never overwritten by a subsequent generate-title call.
  • Calling generate-title on a chat that already has TitleGeneratedAt set is a no-op unless TitleEditedAt is absent (i.e., the auto-title can be refreshed, but a manual rename cannot be undone by automation).
New chat  ──► [first message sent]  ──► generate-title called  ──►  "My PDF summary"  (TitleGeneratedAt set)
                                                                           │
                                                              user renames chat
                                                                           │
                                                                    "Custom title"  (TitleEditedAt set)
                                                                           │
                                                            generate-title  →  no-op

Current MVP support:

  • .txt, .md, .markdown are extracted as raw text.
  • .html, .htm are extracted by stripping scripts, styles and tags, then decoding HTML entities.
  • .pdf is extracted page by page and stores page numbers on chunks.
  • .docx is extracted from document paragraphs.
  • .pptx is extracted slide by slide and stores slide numbers on chunks.
  • Corrupt files fail ingestion with ErrorCode = INGESTION_JOB_FAILED and a sanitized ErrorMessage.