Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

RAG Demo (Go)

A small, fully-local Retrieval-Augmented Generation demo. It indexes Markdown files and answers questions through a browser, using a local LLM (Ollama) and local embeddings. Every pipeline stage is hand-rolled on the Go standard library so you can read and learn how RAG works.

Pipeline

  1. Ingest: walk one or more docs dirs (DOC_PATHS) → read *.md → chunk → embed → in-memory vector store (persisted to INDEX_PATH, reloaded and incrementally updated on restart).
  2. Retrieve: embed the question → cosine similarity → top-K chunks.
  3. Generate: build a prompt with retrieved context → chat model → answer.
  4. Serve: minimal web UI + JSON API.

Prerequisites

  • Go 1.22+ (tested with 1.27)
  • Ollama running locally, with models pulled:
    • ollama pull nomic-embed-text (embeddings)
    • ollama pull qwen2.5:7b (chat)

Run

go build -o output/ask-my-docs .
./output/ask-my-docs

For development tasks, install Task and run task build to build or task dev to start the development server. Run task prepare to install the development tools used by the git hooks and enable those hooks.

Then open http://localhost:8080.

Configuration can be provided via a config.yaml file and/or environment variables (environment variables take precedence over file values).

Config file lookup order:

  1. --config / -c /path/to/config.yaml (relative or absolute)
  2. config.yaml (or config.yml) in the current working directory
  3. OS-specific global path:
    • Windows: %APPDATA%\ask-my-docs\config.yaml
    • macOS/Linux: ~/.config/ask-my-docs/config.yaml

The working directory can be overridden with --cwd /path/to/dir.

Example config.yaml:

doc_paths:
  - ./docs
  - ./more-docs
api_base: http://localhost:11434/v1
chat_model: qwen2.5:7b
port: 8080

doc_paths can also be given as a single comma-delimited string (same format as DOC_PATHS below) if you prefer not to use a YAML list.

Environment variables (override file values):

Var Default
DOC_PATHS ./docs
API_BASE http://localhost:11434/v1
API_KEY (empty)
CHAT_MODEL qwen2.5:7b
EMBED_MODEL nomic-embed-text
TOP_K 4
PORT 8080
CHUNK_SIZE 800
CHUNK_OVERLAP 100
MAX_FILES 0 (no limit)
INDEX_PATH ./index.json
INDEX_WATCH_SECONDS 30

API_BASE may point at any OpenAI-compatible provider (OpenAI, LM Studio, vLLM, ...).

Quick demo (subset)

Point DOC_PATHS at your own Markdown corpus — one folder, or a comma-delimited list of folders in different locations on the device. For a fast first run over a subset, use MAX_FILES:

DOC_PATHS=/path/to/docs MAX_FILES=50 ./ask-my-docs
DOC_PATHS=/path/to/docs,/another/path/to/more-docs ./ask-my-docs

Project layout

main.go             minimal entrypoint shim (installability)
cli/run.go          application logic + embedded web UI
cli/web/index.html  chat UI (embedded)
cli/internal/config env- and config.yaml-based configuration
cli/internal/chunker text chunking
cli/internal/llm    OpenAI-compatible client (embed + chat)
cli/internal/vectorstore in-memory cosine-similarity store
cli/internal/ingest document ingestion
cli/internal/rag    RAG orchestration + prompt building
specs/ask-my-docs   requirements, design, tasks

Tests

go test ./...

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages