Skip to main content

CLI tool for managing and querying internal knowledge files via SQLite FTS5 + optional LLM rerank.

Project description

qkb — local knowledge-base CLI

A small CLI for ingesting and querying local knowledge files (markdown, plain text, JSON, YAML, CSV) using SQLite FTS5 BM25, with optional LLM-powered summarization on ingest and reranking on query.

Install

Requires Python 3.12+ and uv.

git clone <this-repo>
cd qkb_trial
uv sync
uv pip install -e .

After install, qkb is on your PATH. (Or run any command via uv run qkb ….)

Quick start

# Initialize the database (creates ~/.qkb/index.sqlite)
qkb init

# Ingest some files
qkb ingest examples/

# See what's there
qkb list
qkb status

# BM25 search — no LLM required
qkb search "user_id"
qkb search "Postgres"

# Show a single document's metadata + chunk layout
qkb show 1

# Drop a document
qkb delete 1

LLM features (optional)

With an LLM configured, ingest stores a generated summary and tags per document, and qkb query does BM25 → LLM rerank for higher-quality results.

Configure once via env vars or qkb config set:

# OpenAI
export QKB_LLM_PROVIDER=openai
export QKB_LLM_MODEL=gpt-4o-mini
export QKB_LLM_API_KEY=sk-...

# Or local Ollama
qkb config set llm_provider ollama
qkb config set llm_base_url http://localhost:11434/v1
qkb config set llm_model llama3.1:8b

# Then:
qkb ingest examples/
qkb query "how do we handle authentication?"

qkb config list prints the effective configuration. Env vars override ~/.qkb/config.toml.

Commands

Command Purpose
qkb init Create the data directory and database
qkb ingest <paths>... [-r] [--no-llm] [--force] Ingest files or directories
qkb list [--format md] [--json] List ingested documents
qkb show <id|path> Show metadata and chunk layout
qkb delete <id|path> Remove a document
qkb reindex [<path>] [--force] Reprocess changed (or all) documents
qkb search <query> [-n 20] [--json] BM25 search, no LLM needed
qkb query <question> [-n 5] [--pool 20] [--json] BM25 → LLM rerank
qkb status Database stats
qkb config list|get|set Read/write configuration

Storage

Single SQLite file at ~/.qkb/index.sqlite (override with QKB_DATA_DIR or QKB_DB_PATH). Schema: documents (one row per file), chunks (header- or window-bounded fragments), chunks_fts (FTS5 BM25 index over chunk content + heading + summary).

Supported formats

Extension Strategy
.md, .markdown Split by H1/H2/H3 headings; long sections sliding-windowed
.txt, .text Sliding 800-char windows with 100-char overlap
.json Flattened to key.path: value lines per leaf
.yaml, .yml Flattened to key.path: value lines per leaf
.csv One chunk per row, formatted row N: col=val; …

Testing

pytest -q

The test suite uses an in-memory SQLite database and a mocked LLM client — no network required.

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

qkb-0.0.1.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

qkb-0.0.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file qkb-0.0.1.tar.gz.

File metadata

  • Download URL: qkb-0.0.1.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for qkb-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a3529cbd7197a6ee4e57f411ae69dfb8d7bee631e424c28cef3729081cf4a469
MD5 69c70784c961279687034f4e7d250e07
BLAKE2b-256 2dc8677a814e6cccf112a133b3e45950618c62665cd084450e58d72563521a88

See more details on using hashes here.

File details

Details for the file qkb-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: qkb-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for qkb-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66d66594a383dadd195d9148db3f0b7a32c7837ac99d167035a462f2100eb0ef
MD5 44929b64dda8534251ca76310faffb29
BLAKE2b-256 aabaf4a7bce6c839a0dbdeff4b59e48d3150cd018f4019e451d6778c514c298c

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