Skip to content
Projects

About

Three runnable AI engineering projects: traceable RAG, prompt evaluation, guarded NL2SQL. 三个可运行的 AI 工程项目:可追溯 RAG、提示词评测与受守护的 NL2SQL。

AI & Machine Learning

How these counts are measured

What you can do

  • InsightRAG - 旗舰 · RAG - 混合检索、可插拔嵌入适配器、证据回放、逐句引用校验、人工忠实度与金标评测 - 30 - 评测 JSON
  • PromptLens - 轻量 · LLM 评测 - 不可变提示词版本、可复现实验、失败隔离与重试、成本估算、重复运行稳定性 - 39 - 对比报告
  • DataChat BI - 轻量 · AI + 数据安全 - 自然语言到只读 SQL 的完整安全边界,含受控多表 JOIN - 58 - 图表报告

Measured star growth

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.en.md

Original

AI Portfolio · Three Runnable AI Engineering Projects

中文 | English

Python Tests Offline CI

A portfolio for AI application engineering roles: one flagship retrieval-augmented generation project plus two lightweight projects, each focused on a distinct engineering concern. Every project ships with complete source code, deterministic demo data, automated tests, and inspectable artifacts. No API key is required by default, and rule-based simulation is never presented as "intelligence".

These are not screenshots or concept mockups. Every metric in this repository can be reproduced with the commands below, and every limitation is stated explicitly in the docs and in the UI.

Features

Three runnable projects, each focused on one engineering concern: traceable RAG, reproducible prompt evaluation, and guarded NL2SQL analytics. All demos run offline by default.

Project Role Core engineering problem Tests Artifacts
InsightRAG Flagship · RAG Hybrid retrieval, pluggable embedding adapter, evidence replay, sentence-level citation validation, human faithfulness and gold-set evaluation 30 Evaluation JSON
PromptLens Lightweight · LLM evaluation Immutable prompt versions, reproducible experiments, failure isolation and retries, cost estimation, repeated-run stability 39 Comparison report
DataChat BI Lightweight · AI + data safety A complete safety boundary from natural language to read-only SQL, including guarded multi-table joins 58 Chart report

Sub-project READMEs are currently in Chinese; commands, configuration keys, and artifact formats are language-independent.

Installation

Requires Python 3.13. Install the dependencies with pip:

python -m pip install -r requirements.txt

FastAPI + uvicorn power the two web services; httpx is used only by API tests. PromptLens and all three core demos have zero third-party dependencies.

Usage

Start both web services and open the dashboard:

# InsightRAG   http://127.0.0.1:8001
# DataChat BI  http://127.0.0.1:8002
python start_all.py

Each project can also run standalone:

cd insightrag   && python demo.py --eval-output artifacts/evaluation.json
cd promptlens   && python demo.py
cd datachat_bi  && python demo.py

start_all.py listens on 127.0.0.1 only, checks ports and dependencies before starting, and cleans up only the processes it spawned.

Demo

  • Open the portfolio dashboard index.html locally, or the deployed GitHub Pages version: https://8hjkkwikl8.github.io/ai-portfolio/.
  • Run python start_all.py for the two local web demos: the InsightRAG knowledge-base QA UI and the DataChat BI analytics UI.
  • Run python verify_all.py to regenerate the evaluation JSON, the PromptLens comparison report, and the DataChat chart report; every artifact opens offline in a browser or editor.
  • No account or API key is needed for any demo.

Project Details

InsightRAG · Traceable Chinese Knowledge-Base QA

The most common failure of knowledge-base QA is not "no answer" but "a plausible answer with no verifiable basis". InsightRAG separates retrieval, evidence, answering, and metrics into independently inspectable stages:

  • Character-offset chunking; every piece of evidence keeps its source, chunk_id, and original character range, so it can be replayed against the source text.
  • BM25 and a lightweight hashed character n-gram vector run in parallel and are fused with RRF; the hashed vector is not presented as a neural semantic embedding. Setting INSIGHTRAG_EMBEDDING_* switches the vector channel to an OpenAI-compatible embedding endpoint; the default stays fully offline.
  • Offline extractive answering; with an OpenAI-compatible endpoint configured, online generation is available, but sentences without valid citation IDs are filtered out, and the answer falls back to the offline summary if none remain.
  • Gold-set evaluation reports Recall@k, MRR, citation-ID validity, human faithfulness, and latency; faithfulness annotations are matched by answer SHA-256, and unlabeled or stale cases are recorded as N/A instead of a fake 100%.
  • SQLite persistence with whole-source replacement, so re-ingestion never accumulates duplicate corpus.

The demo set contains 3 Chinese policy documents, 13 chunks, and 12 gold questions. Current results: Recall@3 = 1.0, MRR = 1.0, citation-ID validity = 1.0, human faithfulness = 1.0 (only 6 of 12 cases are annotated; the rest are N/A), average latency ≈14 ms (varies by machine). These numbers validate the pipeline only and say nothing about production corpora. See insightrag/README.md (Chinese).

PromptLens · Prompt Versioning and Reproducible Evaluation

If a prompt change is justified only by "it feels better", it can neither be reviewed nor defended. PromptLens pins prompt versions by content hash, datasets by SHA256, and model parameters by a run manifest, then produces comparable metrics and an HTML report:

  • Immutable version registry with strict template-variable checks; missing variables abort the run.
  • Three transparent metrics — exact_match, contains, regex — with per-tag breakdowns; failed samples score 0 on applicable metrics and never disappear from the denominator.
  • Per-item failure isolation, timeouts, and bounded exponential backoff; 408/429/5xx are retryable, other 4xx errors are permanent and not retried.
  • Audited fields such as model and messages cannot be overridden by model_params.
  • Optional pricing config produces cost estimates and comparison deltas, labeled as estimates based on heuristic character-based token counts — not vendor invoices.
  • The same config can be repeated N times with mean/range summaries and per-run references; mock runs must share the same reproducibility hash, and the report states that repeated runs are not statistical significance.
  • All dynamic report content is HTML-escaped; the report is a single offline-viewable file.

In the bundled example, exact_match rises from 7.1% to 92.9%. This comes from a deterministic mock provider and only proves the evaluation pipeline works — it is not evidence of real model or prompt quality. Real conclusions require a configured API and re-testing on an independent held-out set. See promptlens/README.md (Chinese).

DataChat BI · Natural Language to Safe SQL

Getting a model to write SQL is easy; ensuring it can only read, only touch allowlisted tables, and never silently drop user-specified filters is the hard part. DataChat BI implements the safety boundary as multiple layers:

  • Lexical and structural pre-checks: a single SELECT/WITH only; comments, multi-statements, write keywords, and non-allowlisted functions are rejected.
  • A three-table allowlist (orders, products, channels) with guarded joins: only the validated dimension relationships orders.category = products.category and orders.channel = channels.channel are permitted; unknown tables, unknown columns, and comma joins are rejected.
  • Table, column, and function allowlists, bound parameters, and automatic LIMIT injection or tightening.
  • Execution uses a read-only URI, PRAGMA query_only, the SQLite authorizer, and progress-handler timeouts — bypassing the pre-check is not the end of the story.
  • Local JSONL audit events record the question, planner mode, candidate and guarded SQL hashes, guard outcome, row count, and latency; raw SQL, bound parameters, and exception messages are excluded.
  • The offline rule planner matches complete question patterns only; extra conditions such as "East China region only" are explicitly rejected rather than silently ignored.
  • Chinese web UI with inline SVG charts and no external CDN dependencies.

Demo data: 48 deterministic orders plus two dimension tables, 9 question types, 8 charts. Total revenue is 612,360.0; the top category by quantity is smart home (智能家居), and the top channel by quantity is Tmall (天猫); join questions aggregate revenue by product line and channel type. See datachat_bi/README.md (Chinese).

Testing

127 automated tests plus three offline demos; any test or demo failure makes the verifier exit non-zero.

python verify_all.py
  • Test breakdown: InsightRAG 30, PromptLens 39, DataChat BI 58 — all built on unittest.
  • Run a single project: cd insightrag && python -m unittest discover -s tests -q (same for the other projects).
  • GitHub Actions runs the same verification on ubuntu-latest and windows-latest with Python 3.13; see ci.yml.

Architecture

All three projects share one structural rule: untrusted model output must cross a boundary. Retrieved evidence is replayable, generated answers pass sentence-level citation checks, and model-written SQL goes through layered guards before the read-only execution layer; every metric keeps the inputs and hashes needed to re-check it.

ai-portfolio/
├─ index.html              # Portfolio dashboard (open locally)
├─ start_all.py            # Start InsightRAG and DataChat BI with health checks
├─ verify_all.py           # 127 tests + three offline demos
├─ requirements.txt
├─ insightrag/             # Flagship: hybrid retrieval, citation validation, gold-set evaluation
├─ promptlens/             # Lightweight: prompt versioning and reproducible evaluation
└─ datachat_bi/            # Lightweight: guarded NL2SQL analytics

Deployment

  • The static dashboard index.html is published through GitHub Pages: https://8hjkkwikl8.github.io/ai-portfolio/.
  • The two FastAPI services are local demos only; there is no public hosted backend, and the repository contains no accounts, auth, or production deployment config.
  • CI runs tests and offline demos only; it does not deploy.

Shared Design Principles

Offline-first, not offline-faked intelligence. Core pipelines run with no network and no keys. Rules, hashing methods, and mocks are labeled as what they are; real models are replaceable adapters, not a prerequisite for the demo.

Untrusted output must cross a boundary. Model answers cannot invent sources, candidate SQL cannot bypass the guard, and experiment parameters cannot override audited requests. Every project treats model output as untrusted input.

Results must be reproducible and refutable. Original offsets, dataset hashes, run manifests, and per-item outputs are preserved; metric definitions and limitations are shown together. Small demo datasets are a deliberate choice: every result can be checked by hand.

Honesty Boundaries

  • InsightRAG's corpus is 3 demo documents; Recall/MRR do not extrapolate to production knowledge bases, and citation-ID validity checks numbering only — it is not semantic faithfulness. Human faithfulness covers only 6 manually reviewed offline snapshots; unlabeled or stale cases are N/A, and it does not represent online generation or production faithfulness.
  • PromptLens example metrics come from a mock provider and validate the pipeline only; they are not evidence of model quality improvement.
  • DataChat BI's 48 orders and rule-based phrasings demonstrate a safety boundary; joins are limited to allowlisted dimension relationships and are not general natural-language understanding; the offline mode rejects uncovered phrasings.
  • All three projects are single-machine demos without accounts, access control, distributed indexing, or production-grade observability.

Environment and Dependencies

  • Python 3.13 (modern type annotations; older versions are untested).
  • FastAPI + uvicorn for the two web services.
  • httpx, used only by API tests.
  • PromptLens and all three core demos have zero third-party dependencies.
  • No external front-end assets; pages, reports, and charts open offline.

Optional: Connect Real Models

All three projects extend through an OpenAI-compatible endpoint and never go online by default:

export OPENAI_BASE_URL="https://your-endpoint/v1"
export OPENAI_API_KEY="..."        # May be empty for local compatible servers
export OPENAI_MODEL="your-model"

InsightRAG calls online generation only when a query explicitly includes "online": true. For PromptLens, set provider to openai_compatible in the run config. DataChat BI enables its LLM planner when OPENAI_API_KEY and OPENAI_MODEL are present, but candidate SQL must still pass the same guard and read-only execution layer. InsightRAG's vector channel can switch to a remote embedding service via INSIGHTRAG_EMBEDDING_BASE_URL, INSIGHTRAG_EMBEDDING_MODEL, and INSIGHTRAG_EMBEDDING_API_KEY; if any of the three is missing, the offline hashed vector remains in use.

Contributing and License

Reproducible improvements with clear engineering boundaries are welcome. Read the contributing guide and code of conduct before participating. This project is available under the MIT License.

Explore related projects

Loading…