Skip to main content

AI-powered quant research knowledge base & brainstorm agent

Project description

Quant_LLM_Wiki

English | 简体中文

A Karpathy-shaped wiki-first knowledge base for quantitative investment research.

Python License LLM ChromaDB

Quant_LLM_Wiki turns WeChat articles, web pages, and research PDFs into an LLM-built Markdown knowledge base for quantitative research. It follows Andrej Karpathy's LLM-built KB method: a raw/ ingest layer, an LLM-compiled wiki/ of concept articles, and a schema/ that the LLM and tools both follow. Vector RAG is preserved as a fallback substrate, not the primary retrieval path. Three durable verbs — ingest, query, lint — drive everything. A built-in Rethink Layer scores novelty and quality of brainstormed ideas before output.

The goal is research inspiration and cross-document idea combination, not producing trade-ready strategies.

Features

  • Multi-source ingestion — single URLs, batch URL lists, local HTML, or PDFs; warns on re-ingesting rejected sources
  • LLM enrichment — extract idea blocks, transfer targets, combination hooks, failure modes; concurrent with configurable parallelism
  • Wiki-first retrieval — both ask and brainstorm query stable concepts first; vector RAG runs only as fallback
  • Rethink Layer — post-generation novelty (vector similarity) + quality (LLM-as-judge) scoring on brainstormed ideas
  • Schema-enforced wikiwiki_lint checks required frontmatter, sections, and source anchors on every run; --fix auto-repairs via LLM
  • Query → wiki feedback — every ask/brainstorm logs back into the wiki; lint --maintain distills logs into gap-filling suggestions
  • Interactive agent — LangGraph ReAct agent with 12 tools and real-time progress streaming
  • Provider-agnostic — any OpenAI-compatible LLM (Zhipu GLM, DeepSeek, Moonshot, Qwen, OpenAI, Ollama, etc.)
  • Local-first — all data as Markdown + ChromaDB on disk

For the full architecture, three-verb pipeline, retrieval invariants, and design principles, see docs/architecture.md.

Quick start

Pick one install flow and stay in that column.

A. pipx (end users) B. git clone (developers)
When to use Just want to run qlw and build a personal KB. Read/edit source, run tests, contribute.
Repo locally? No Yes
Workspace Any dir (or $QLW_KB_ROOT) The clone itself by default
.env location <workspace>/.env (auto-loaded from CWD) <workspace>/.env (auto-loaded from CWD)
schema/ One-time fetch (below) Already in the clone

1. Install

# A. pipx (recommended)
pipx install quant-llm-wiki

# B. git clone + editable install
git clone https://github.com/jackwu321/Quant_LLM_Wiki.git
cd Quant_LLM_Wiki && python3 -m venv .venv && source .venv/bin/activate
pip install -e .

pipx ≥ 1.5 required (older pipx ships pip 24.0 which mis-parses langgraph's newer wheel metadata). If install fails with ResolutionImpossible, upgrade pipx first: python3 -m pip install --user --upgrade --break-system-packages pipx && hash -r.

2. Pick a workspace

qlw writes data under whichever directory it considers your KB root, resolved in this order: explicit --kb-root arg → $QLW_KB_ROOT → current working directory.

# pipx users — bootstrap a workspace and fetch schema/
mkdir -p ~/my-kb && cd ~/my-kb
export QLW_KB_ROOT="$PWD"
curl -fsSL https://github.com/jackwu321/Quant_LLM_Wiki/archive/refs/heads/main.tar.gz \
  | tar xz --strip=1 --wildcards "*/schema/*" "*/llm_config.example.env"

# clone users — the clone IS the workspace
cd Quant_LLM_Wiki

3. Configure the LLM

cp llm_config.example.env .env
# Edit .env with your API key and provider settings

.env is auto-loaded from $QLW_KB_ROOT/.env$(pwd)/.env → the package directory. Or export directly in your shell. See llm_config.example.env for provider examples.

4. Try the worked example (no real research data needed)

cd examples/tiny_kb
export QLW_KB_ROOT="$PWD"

qlw enrich            # LLM-enrich the pre-seeded sample articles
qlw embed             # build the vector index
qlw compile           # compile the wiki
qlw ask --query "What signals do these articles describe?"
qlw brainstorm --query "Combine momentum and sector ETF rotation"

See examples/tiny_kb/README.md for what gets produced and where to look.

5. Run on your own articles

qlw ingest --url "https://mp.weixin.qq.com/s/..."   # WeChat / web URL
qlw ingest --html-file saved.html                    # saved page
qlw ingest --pdf-file paper.pdf                      # research PDF
qlw ingest --url-list urls.txt                       # batch from a list

qlw enrich --limit 10
qlw embed
qlw ask --query "What momentum factors are discussed?"
qlw brainstorm --query "Combine momentum and volatility timing for ETF rotation"

Ingestion auto-runs compile and embed after success. Each URL has a 120 s ceiling; each LLM enrichment has 360 s. Override with INGEST_URL_TIMEOUT / LLM_ARTICLE_TIMEOUT.

Wiki maintenance

qlw lint                       # schema + health audit
qlw lint --fix                 # LLM auto-repair of non-compliant concepts
qlw lint --maintain            # gap analysis: unmapped sources, under-supported, stale
qlw lint --maintain --apply    # apply query-derived state updates (idempotent)

Agent mode

qlw agent                                       # interactive REPL
qlw agent --query "list all articles"           # one-shot
qlw agent --query "brainstorm: factor timing + risk parity"

The agent dispatches the 12 tools listed in docs/architecture.md#agent-layer — ingest, enrich, list/review, embed, query, compile, audit, and read.

Configuration

Variable Default Description
LLM_API_KEY Your API key
LLM_BASE_URL https://open.bigmodel.cn/api/paas/v4 OpenAI-compatible endpoint
LLM_MODEL glm-4.7 Chat model
LLM_EMBEDDING_MODEL embedding-3 Embedding model
LLM_CONNECT_TIMEOUT 15 Connection timeout (s)
LLM_READ_TIMEOUT 180 Read timeout (s)
LLM_MAX_RETRIES 4 Max retry attempts
LLM_MIN_INTERVAL_SECONDS 2.0 Process-local minimum spacing before LLM requests
LLM_CONCURRENCY 3 Worker parallelism for enrichment

Legacy ZHIPU_* variables are also accepted as fallbacks. On HTTP 429, later requests in the same process honor a shared cooldown (Retry-After header when present).

Article status lifecycle and content_type classification are documented in docs/metadata-schema.md.

Documentation

Running tests

Tests live in the repo, not the wheel — run from a git clone checkout (install flow B).

python3 -m unittest discover -s tests -p 'test_*.py' -v
python3 -m unittest discover -s tests/robustness -p 'test_*.py' -v

The tests/robustness/ suite covers Layer 1 (tool inputs), Layer 2 (workflow integration), Layer 3 (agent routing), and Layer 4 (LLM API timeouts/retries).

Contributing

  1. Fork and create a feature branch
  2. Write tests for new functionality
  3. Ensure python3 -m unittest discover -s tests -p 'test_*.py' passes
  4. Open a Pull Request

License

MIT — see LICENSE.

Disclaimer

Quant_LLM_Wiki is a research tool for generating investment strategy ideas. It does not produce trade-ready strategies or financial advice. All generated ideas require independent validation, backtesting, and risk assessment before any real-world application. Use at your own risk.

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

quant_llm_wiki-0.5.0.tar.gz (147.5 kB view details)

Uploaded Source

Built Distribution

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

quant_llm_wiki-0.5.0-py3-none-any.whl (115.8 kB view details)

Uploaded Python 3

File details

Details for the file quant_llm_wiki-0.5.0.tar.gz.

File metadata

  • Download URL: quant_llm_wiki-0.5.0.tar.gz
  • Upload date:
  • Size: 147.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quant_llm_wiki-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ce9bb186e8d70fb4cc32de6084f1addca78abbaf2bc00b80d40a0645c964d10c
MD5 3abc9166da2ebb59ef8a96fcc861f637
BLAKE2b-256 c4da088fd7f83f541dff594762387f5428d7a7603a6ffc09f40a078f8af50c07

See more details on using hashes here.

Provenance

The following attestation bundles were made for quant_llm_wiki-0.5.0.tar.gz:

Publisher: publish.yml on jackwu321/Quant_LLM_Wiki

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quant_llm_wiki-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: quant_llm_wiki-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 115.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quant_llm_wiki-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19e4d01e54afa6bdc547a9360b4d85f64157208b0b22339730a156a0353e704e
MD5 a0dec11decf66c22f1c0e3d9125b5258
BLAKE2b-256 721e937eb6cfd6c3d3488339d7dca8d2c61be8e0da58e060818d05c499995b4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for quant_llm_wiki-0.5.0-py3-none-any.whl:

Publisher: publish.yml on jackwu321/Quant_LLM_Wiki

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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