How inegmdev/qrag works
1. What this repo is
- qrag is a local-first indexing and retrieval system for teams: one person builds semantic databases once, then everyone else downloads and queries them from AI agents.
- The core boundary is between database preparation and database consumption.
2. Primary runtime and packaging
- The main implementation is a Python package under src/qrag.
- User entry points are exposed through the CLI (src/qrag/cli.py), with supporting config, storage, parsing, embedding, and integration modules.
- Packaging is handled with standard Python tooling (pyproject.toml, setup.py, uv.lock), and there is also an npm/ package present for JavaScript-side distribution/integration.
3. Build/indexing pipeline
- The build flow takes local input directories (qrag build -i ... -o version) and turns them into versioned indexes.
- Source code goes through doc_parser.py, chunker.py, and likely tree-sitter-based symbol extraction before being written into a code-oriented database.
- Documentation files are parsed into section/chunk units and stored separately so code and docs can be searched independently.
4. Embeddings and semantic search
- embedder.py is the semantic layer: it generates embeddings locally rather than calling an external service.
- The README indicates the bundled model is all-MiniLM-L6-v2, with optional GPU acceleration for larger installs.
- Search is therefore a hybrid of symbolic structure plus vector similarity.
5. Storage model
- Each published version is stored locally under ~/.qrag/<version>/.
- The two main artifacts are code.db and docs.db, both SQLite databases.
- The active version set is separate from storage; users can keep multiple versions installed and search across all of them simultaneously.
6. Query path
- The CLI supports search, search code, search docs, and search symbol.
- database.py is the retrieval boundary: it likely merges results from active databases, deduplicates them, and returns ranked matches.
- Symbol lookup is exact/structural, while code/docs search is semantic.
7. Distribution and team sharing
- github_distribution.py handles the “hub” workflow: listing versions, downloading them, pushing them, and deleting local copies.
- The repository is configured through QRAG_GITHUB_URL, and GitHub auth is required via gh or GITHUB_TOKEN.
- This makes the architecture explicitly publisher/consumer rather than centralized SaaS: the team hosts databases in a GitHub repo and clients fetch them.
8. AI agent integration
- mcp_server.py exposes qrag as tools to external AI clients.
- The README mentions Claude and Gemini CLI support via qrag ai setup, which installs or configures an MCP-style tool bridge.
- The integration boundary is local: the agent calls qrag-installed tools on the user machine, not a remote API.
9. User-facing interfaces
- The main user interface is the CLI, but there is also a tui.py module for terminal-based interaction.
- status and info provide operational visibility into which versions are active and whether the databases exist locally.
- This is a developer-tooling style application, not a web service.
10. Repository organization for workflows
- docs/ contains the product and architecture docs, including architecture, backlog, handoff, quickstart, and progress tracking.
- issues/ contains issue-sized work items that map onto roadmap features like incremental updates, live folder watching, GPU embeddings, and distribution.
- tests/ covers the main subsystems: chunking, database behavior, integration, and TUI.
11. Build and release pipeline
- GitHub Actions in .github/workflows/ci.yml and publish.yml handle validation and release publication.
- The repo is designed to be installed either for end users or for builders, with separate dependency profiles for CPU vs GPU-heavy builds.
- scripts/download_model.py and tools/afk.py are supporting utilities rather than core architecture.
12. Important architectural takeaway
- The system is centered on local immutable-ish versioned indexes plus a GitHub-backed distribution channel.
- All runtime behavior flows from that: build locally, store per version, activate one or more versions, search across them, and expose the result to AI agents through a local MCP integration.
Main entry points: cli.py CLI · database.py Database · github_distribution.py GitHub Distribution · chunker.py Chunker
Components 17
Build & Indexing
Local preparation pipeline that turns source directories into versioned databases.
- Doc Parser · Turns documents into searchable sections and chunks.
src/qrag/doc_parser.py - Chunker · Splits content into retrieval-sized units for indexing.
src/qrag/chunker.py - Embedder · Generates local semantic embeddings for code and docs.
src/qrag/embedder.py - Config · Holds runtime and storage configuration for builds and queries.
src/qrag/config.py
Databases
Versioned local SQLite stores and retrieval logic.
- Database · Retrieval boundary that merges active versions and ranks results.
src/qrag/database.py
Sharing
GitHub-backed publishing and installation of database versions.
- GitHub Distribution · Lists, downloads, publishes, and removes versioned database bundles.
src/qrag/github_distribution.py
Interfaces
User and agent entry points for search and control.
- CLI · Main command-line entry point for build, search, status, and info workflows.
src/qrag/cli.py - TUI · Terminal interface for interactive usage.
src/qrag/tui.py - MCP Server · Exposes qrag capabilities to external AI clients through local tools.
src/qrag/mcp_server.py
Packaging
Python and npm distribution surfaces.
- Packaging · Python packaging and installation metadata for the project.
setup.py - Pyproject · Primary Python project and dependency configuration.
pyproject.toml - npm Package · JavaScript-side package and distribution integration surface.
npm/package.json
Other components
- README · High-level product and usage documentation.
README.md - Architecture · System architecture and design notes.
docs/ARCHITECTURE.md - Backlog · Planned work items and roadmap decomposition.
docs/BACKLOG.md - CI · Validation workflow for tests and checks.
.github/workflows/ci.yml - Publish · Release workflow for publishing distributable artifacts.
.github/workflows/publish.yml
Connections 20
- CLI → Config: loads · CLI reads runtime settings and active version configuration.
- CLI → Doc Parser: builds docs · Build commands parse documentation inputs into indexed units.
- CLI → Chunker: builds code · Build commands chunk code-oriented inputs for indexing.
- CLI → Embedder: embeds · Build and search flows use local embeddings.
- CLI → Database: queries · Search commands route through the retrieval boundary.
- CLI → GitHub Distribution: syncs · CLI supports version listing, download, publish, and cleanup.
- CLI → TUI: offers · CLI and TUI provide alternative local user interfaces.
- CLI → MCP Server: exposes · CLI can configure local agent-tool integration.
- Doc Parser → Chunker: normalizes · Document parsing feeds chunking and sectionization.
- Chunker → Embedder: vectors · Chunked content is converted into embeddings.
- Embedder → Database: stores · Semantic representations are written into the local databases.
- Database → GitHub Distribution: fetches versions · Active or missing versions can be pulled from GitHub-backed storage.
- GitHub Distribution → Database: installs · Downloaded versioned databases become queryable local stores.
- README → CLI: documents · README describes the primary commands and workflows.
- Architecture → Database: describes · Architecture docs explain the versioned storage and retrieval model.
- Backlog → GitHub Distribution: plans · Backlog tracks sharing, sync, and publish enhancements.
- Pyproject → Packaging: packages · Python packaging metadata drives installation and build behavior.
- npm Package → CLI: integrates · npm package supports JavaScript-side consumption and integration.
- CI → Packaging: validates · CI checks packaging and project integrity.
- Publish → GitHub Distribution: releases · Publish workflow ships distribution artifacts and release outputs.