Skip to main content

Ask anything about any codebase. Local, private, fast.

Project description

Polymath

Ask anything about any codebase. Instant answers, zero data leaks.

Python License


What is Polymath?

Polymath is a local-first codebase intelligence CLI. Point it at any repository — public or private — and ask questions in plain English. It indexes your code into a local vector database, retrieves the most relevant chunks, and answers with exact file citations and line numbers.

Your code never leaves your machine.

pm cd https://github.com/pallets/click
pm ask "how does argument parsing work?"
## Argument Parsing in Click

Click's argument parsing is handled in `src/click/core.py` lines 1089-1134.
When a command is invoked, `Command.make_context()` creates a `Context` object
and calls `Command.parse_args()` which delegates to each parameter's
`Parameter.consume_value()` method...

## How to use this in your codebase

from click import argument, command

@command()
@argument('filename')
def process(filename):
    click.echo(f'Processing {filename}')

Why Polymath?

Feature Polymath GitHub Copilot ChatGPT
Works on private repos ✅ Local only ❌ Sends to GitHub ❌ Sends to OpenAI
No internet required ✅ Fully offline ❌ Cloud dependent ❌ Cloud dependent
Remembers conversation ✅ Per-repo history ❌ No memory ❌ Resets each chat
Any language ✅ All languages ✅ All languages ✅ All languages
Free ✅ Always ❌ $10/month ❌ $20/month
Cites exact lines ✅ Always ❌ No citations ❌ No citations

Installation

Prerequisites

  • Python 3.11+
  • Docker Desktop

Install

pip install polymath-cli

First time setup

pm init

This spins up a local Postgres and Qdrant instance via Docker. Run once, never again.

Health check

pm doctor

Commands

Indexing

pm cd .                                      # index current directory
pm cd /path/to/project                       # index any local path
pm cd https://github.com/user/repo           # clone and index a public repo
pm refresh                                   # re-index the active repo
pm rm <repo-name>                            # remove an indexed repo

Asking Questions

pm ask "how does authentication work?"
pm ask "where is the database connection set up?"
pm ask "what happens when a user signs up?"
pm explain src/auth.py                       # explain an entire file
pm diff                                      # explain the last git commit

Reading Code

pm cat src/auth.py                           # read file with syntax highlighting
pm cat src/auth.py:23-45                     # read specific lines
pm find "jwt"                                # find all chunks containing a keyword

Conversation

pm history                                   # show conversation history
pm clear                                     # clear conversation history
pm save my-session                           # save conversation to markdown
pm export                                    # copy conversation to clipboard

Repo Management

pm ls                                        # list all indexed repos
pm status                                    # show active repo and stats

Setup

pm init                                      # first time setup
pm doctor                                    # check Docker, Postgres, Qdrant health

How it works

pm cd <repo>
  → crawl all files (respects .gitignore)
  → chunk code at 50-line boundaries
  → embed each chunk with BGE-base-en-v1.5
  → store vectors in local Qdrant
  → store metadata in local Postgres

pm ask "question"
  → embed the question
  → search Qdrant for top 8 most relevant chunks
  → fetch full chunk content from Postgres
  → inject context + conversation history into prompt
  → stream answer from Gemini 2.5 Flash
  → save to conversation history

All vector search and storage happens locally. Only the question + relevant code snippets are sent to Gemini to generate the answer.


Architecture

polymath/
  pm/
    cli.py           # Typer commands — the user interface
    agent/
      ask.py         # retrieval + LLM + streaming answer
    indexer/
      crawler.py     # file discovery, respects .gitignore
      chunker.py     # 50-line chunks with overlap
      indexer.py     # orchestrates the full indexing pipeline
    db/
      models.py      # SQLAlchemy: repos, files, chunks, conversations
      queries.py     # all Postgres operations
      database.py    # engine + session factory
    vector/
      store.py       # Qdrant operations + BGE embeddings
    utils/
      init.py        # pm init — Docker setup
      doctor.py      # pm doctor — health checks
      state.py       # active repo tracking via ~/.polymath/.env

Data stores:

  • ~/.polymath/ — config, docker-compose, .env
  • ~/.polymath/repos/ — cloned GitHub repos
  • Postgres (port 5433) — repo metadata, file records, chunks, conversation history
  • Qdrant (port 6334) — vector embeddings for semantic search

Security

Polymath is designed with privacy as a first principle.

  • Code stays local — indexing runs entirely on your machine
  • Vectors stay local — Qdrant runs in Docker on your machine
  • Only snippets leave — when you ask a question, the relevant code chunks (not your entire codebase) are sent to Gemini to generate the answer
  • No accounts — no login, no tracking, no telemetry
  • Private repos — clone them yourself, pm cd the local path. Nothing is uploaded

If you need 100% air-gapped operation, swap Gemini for a local Ollama model — only the ask.py file needs changing.


Configuration

Polymath stores all config in ~/.polymath/.env:

DATABASE_URL=postgresql://polymath:polymath@localhost:5433/polymath
QDRANT_HOST=localhost
QDRANT_PORT=6334
GEMINI_API_KEY=your-key-here
ACTIVE_REPO_ID=1
ACTIVE_REPO_NAME=myproject

Get a free Gemini API key at aistudio.google.com.


Roadmap

  • Tree-sitter AST chunking — chunk at function/class boundaries for better context
  • Multi-query RAG Fusion — generate query variations for better retrieval
  • pm share — generate shareable links for public repos
  • Web interface — browser-based chat UI
  • Ollama support — 100% offline mode with local LLMs
  • GitHub OAuth — index private repos without cloning manually
  • VS Code extension

Contributing

git clone https://github.com/yourname/polymath
cd polymath
uv install
pm init
pm cd .
pm ask "how does the indexer work?"

License

MIT — do whatever you want with it.


Built with Python, Qdrant, PostgreSQL, BGE embeddings, and Gemini 2.5 Flash.

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

polymath_cli-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

polymath_cli-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file polymath_cli-0.1.0.tar.gz.

File metadata

  • Download URL: polymath_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for polymath_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c2b08ba7a76c3f60a7ed3fcc61b59e6be9a61b2a26621518a137c82f176a8d6c
MD5 b68778b73ee3c9285de42b33137a89bd
BLAKE2b-256 9d953c5523a13cc5bc199887b466fb3a7038d0e92e0f86ebc0feab12592c52d2

See more details on using hashes here.

File details

Details for the file polymath_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: polymath_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for polymath_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 492ef9f8017f14aff7d4f76393bae86eaf8aa7a67561d5b4b8345966683144e8
MD5 9c1fdfa835430c4372da3e29a20682a7
BLAKE2b-256 631153eb9566a3338b41b99273faadeb7dc21153e12ec14d8142bec0430b93ee

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