Skip to main content

Knowledge graph builder for code and product assets with token optimization for LLMs

Project description

mindretriever

Knowledge graph and context-pack tooling for AI-assisted software development.

PyPI version Python License: MIT

What It Solves

Large codebases make LLM workflows noisy and expensive. Sending entire files to an assistant increases token usage, response time, and irrelevant context.

mindretriever solves this by:

  • Building a local knowledge graph of your repo
  • Selecting only task-relevant snippets for each question
  • Returning a token-optimized context pack for bug fix, feature, refactor, test, review, and optimization workflows
  • Tracking measurable token and cost savings over time

Key Features

  • Local-first architecture (no external indexing service required)
  • Multi-language extraction across backend and frontend assets
  • FastAPI service for automation and tool integration
  • MCP server for native use in VS Code Copilot Chat and Cursor
  • Incremental runs via file-hash cache
  • Local SQLite history of runs, graph entities, and savings metrics

Install

Basic install:

pip install mindretriever

Install with MCP support (recommended for VS Code/Cursor chat integration):

pip install "mindretriever[mcp]"

Verify CLI:

mindretriever --help

If command resolution fails on Windows:

python -m mindretriever --help

Quick Start (CLI + API)

1) Analyze a repo

mindretriever run .

Windows-safe fallback:

python -m mindretriever run .

2) Start API

mindretriever-api

Windows-safe fallback:

python -m uvicorn mindretriever.api:app --host 0.0.0.0 --port 8000

Health check:

curl http://localhost:8000/health

3) Create a context pack for a question

curl -X POST http://localhost:8000/api/context-pack \
  -H "Content-Type: application/json" \
  -d '{
    "run_id": 1,
    "task_type": "bug_fix",
    "query": "Why is checkout timing out after deployment?",
    "token_budget": 6000,
    "include_artifacts": true
  }'

4) Check savings proof

curl http://localhost:8000/api/savings

This returns:

  • Per-query before/after token counts
  • Estimated before/after input cost
  • Aggregate total savings across all recorded queries

Use Directly In VS Code And Cursor (MCP)

mindretriever includes an MCP server so chat assistants can call tools automatically while you ask normal questions.

VS Code setup

Create .vscode/mcp.json:

{
  "servers": {
    "mindretriever": {
      "type": "stdio",
      "command": "python",
      "args": ["-m", "graphmind.mcp_server"],
      "cwd": "${workspaceFolder}",
      "env": {}
    }
  }
}

Cursor setup

Create .cursor/mcp.json:

{
  "mcpServers": {
    "mindretriever": {
      "command": "python",
      "args": ["-m", "graphmind.mcp_server"],
      "cwd": "${workspaceFolder}"
    }
  }
}

Then restart the editor and ask questions normally.

MCP Tools

  • mindretriever_analyze(path=".")
    • Builds graph and stores a run record
  • mindretriever_context(query, task_type="auto", run_id=None, token_budget=8000)
    • Returns task-focused context pack
  • mindretriever_runs(limit=5)
    • Lists recent analysis runs
  • mindretriever_savings(limit=20)
    • Shows token and cost savings evidence from local history

API Overview

Method Endpoint Purpose
GET /health Service health
POST /api/run Run extraction + graph build
POST /api/upload Upload .md, .docx, .sql files
GET /api/runs List run history
GET /api/runs/{run_id}/graph Retrieve graph payload for a run
POST /api/context-pack Get token-aware context pack
GET /api/savings Show local token/cost savings history

Upload field names:

  • Preferred: files
  • Compatibility alias: file

Example upload:

curl -F "files=@architecture.md" -F "files=@schema.sql" http://localhost:8000/api/upload

Supported Inputs

Detection and extraction support

Extension group Coverage
.py Python AST extraction
.sql SQL schema extraction
.js, .jsx, .ts, .tsx TypeScript/JavaScript semantic extraction
.vue, .svelte Section-aware Vue/Svelte semantic extraction
.css, .scss CSS selector extraction
.md, .txt, .rst Heading/concept extraction
.docx Semantic extraction
.go, .java Detected; deeper extraction planned

Vue/Svelte semantic coverage

  • Script/template section-aware parsing
  • Imports and component references
  • Props (defineProps, export let)
  • Emits (defineEmits)
  • Stores ($store references)
  • Slot usage (<slot ...>)

CLI

mindretriever run [path] [--full]
  • Default path: current directory
  • Default mode: incremental
  • --full: force full reprocessing

Legacy aliases kept for compatibility:

graphmind run .
graphmind-api

Output Artifacts

Generated in graphmind-out/:

  • graph.json: portable graph data
  • graph.html: human-readable graph visualization
  • GRAPH_REPORT.md: summary metrics
  • graphmind.db: SQLite database (runs, nodes, edges, savings)
  • cache/file_hashes.json: incremental cache
  • uploads/: uploaded source documents
  • artifacts/: cached context artifacts

Token Savings Methodology

mindretriever records savings on each context request.

Definitions:

  • full_tokens: tokens if all candidate project files were sent to the LLM
  • pack_tokens: tokens in the generated context pack
  • saved_tokens = full_tokens - pack_tokens
  • savings_pct = saved_tokens / full_tokens * 100

Cost estimates:

  • Uses input-token pricing table (default model: gpt-4o)
  • Stored with each record and aggregated in /api/savings and mindretriever_savings

Token counting:

  • Uses tiktoken when installed
  • Falls back to len(text) // 4 approximation otherwise

Development

git clone https://github.com/RameshJajula/mindretriever.git
cd ramesh-graphmind
pip install -e ".[dev,mcp]"
python -m pytest tests -q

Build and validate package:

python -m build
python -m twine check dist/*

See PUBLISH.md for release steps.

Project Structure

mindretriever/
  __init__.py
  __main__.py
  cli.py
  api.py
graphmind/
  api.py
  cli.py
  mcp_server.py
  token_counter.py
  pipeline.py
  detect.py
  db.py
  context_budget.py
  retrieval_planner.py
  prompt_templates.py
  extractors/
    python_ast.py
    sql_schema.py
    typescript_semantic.py
    vue_svelte_semantic.py
    text_semantic.py
    docx_semantic.py
  graph/
    builder.py
    analytics.py
  exporters/
    json_exporter.py
    html_exporter.py

Compatibility Notes

  • Python 3.10+
  • SQLite is bundled with Python; no external DB required
  • For Windows command resolution issues, use module invocation commands
  • Legacy CLI aliases graphmind and graphmind-api remain available

License

MIT. See LICENSE.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mindretriever-0.2.1.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mindretriever-0.2.1-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

Details for the file mindretriever-0.2.1.tar.gz.

File metadata

  • Download URL: mindretriever-0.2.1.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mindretriever-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1b11dbd418b2d6644b53e6ec14ccbd8bb8d1859acd711de4f6c8daab187613b8
MD5 e0023de96ae22b2c887e2e0b70ea0bc2
BLAKE2b-256 a945cc9983aaf79288236b717d097cbcb83b063246345f1209ab046c375ca9e0

See more details on using hashes here.

File details

Details for the file mindretriever-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mindretriever-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 46.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mindretriever-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0095152b0832e02d5342cbdcf6ae528e87a61507d61b4a1c273f1fc47c3a0e6
MD5 cde20409e29b3f21ddd3a9ac0ed8d108
BLAKE2b-256 8d10f274d8c7b23b283c2817b592c6397239ead01414a025a76b3aa9a39cfa95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page