Spaces:
Paused
Paused
Commit History
-
Create stata/__init__.py
Verified signaturef35603b -
Update src/query_engine.py
Verified signaturea55ad28 -
Update src/prompts.py
Verified signature37ac222
-
Update src/verifier.py
Verified signaturec86d40f -
Update src/verifier.py
Verified signaturef795a1a -
Update src/prompts.py
Verified signature35c5bae -
Update src/config_loader.py
Verified signature003cef4
-
Folder restructure for HF
8e63234 -
Update folder structure for HF deployment
e2f586d
-
Update support for llama/HF models
5044f4c
-
Update llama model name
f16a878 -
Update api-key access for llama model
5a07c19 -
Update model support:
- add meta-llama provider - add support for llama models - add support for HF inference providersc2a725e
-
feat: switch to stable workhorse models (gpt-4.1, sonnet-4-6, gemini-2.5-flash)
- OpenAI: gpt-4.1 (default), gpt-4.1-mini, gpt-4.1-nano - Anthropic: claude-sonnet-4-6 (default), claude-haiku-4-5, claude-opus-4-6 - Gemini: gemini-2.5-flash (default), gemini-2.5-pro, gemini-2.0-flash - GPT-5/reasoning restricted-param handling preserved for manual config - README config example updated to match Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>6d5b557
-
fix: handle GPT-5 restricted parameters (no temperature, developer role)
GPT-5 models do not support custom temperature or the system role, similar to reasoning models. Unified detection via _is_restricted_model() for all models requiring max_completion_tokens and developer role. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>05c53af -
fix: use max_completion_tokens for GPT-5 (replaces deprecated max_tokens)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>549355f -
feat: upgrade to GPT-5 series, increase default max_tokens to 8192
- OpenAI models: gpt-5 and gpt-5-mini only (removed GPT-4 series) - Default max_tokens raised from 2048 to 8192 across all providers - Added o4-mini to reasoning model detection - Updated setup wizard fallback lists and defaults Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>68a6539 -
fix: verification prompt now allows SQL data summarization across rows
The verifier was rejecting valid responses for SQL-heavy queries because check #2 demanded an EXACT data point match for each claim. When the LLM summarizes across 49 SQL rows (e.g., "scores ranged from 3 to 5"), no single row contains that statement, causing repeated verification failure and strict-mode refusal. Updated verification checklist: - Check #2: SQL rows may be legitimately summarized; verify underlying data points exist across rows, not that one row matches verbatim - Check #10: SQL citations may cover an entire dataset/table Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1eac8bc -
fix: Round 17 audit — critical/high bug fixes (5 bugs, cross-checked)
- H1: validate_citations regex now matches References:/Reference/Sources (Primary) - H2: _strip_sql_comments rewritten as state machine, preserves --//**/ inside strings - H3: SQL citation count fixed: 1 source per query, not 1 per row - M1: Context budget now accounts for web context size before local allocation - M2: max_context_chars default aligned to 12000 (was 0 in code vs 12000 in docs) 10 agents dispatched: 5 audit + 3 fix + 2 cross-check. 175/175 tests passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>f9f7706 -
fix: Round 15 — 2 HIGH bugs fixed (sql_count citation audit + reader error handling)
H-1: validate_citations counted all SQL rows as 1 source, causing systematic false "fabricated reference" warnings on multi-row SQL queries. Now counts each row as a separate citable unit. H-2: text.py and csv_tab.py were the only readers without try/except wrappers. A single bad .txt/.csv file would crash the entire ingestion pipeline. Added matching error handling. 174/174 tests passing. Final line-by-line audit by 3 independent agents confirmed all 23 source files are clean. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>a6b3188 -
fix: Round 14 — 28 Tier 1 + Tier 2 bugs fixed across 17 source files
Anti-hallucination integrity (T1): - #100: Detect verification LLM system failure (all calls fail → refuse) - #101: Fix validate_citations SQL/web source matching (dead code → working) - #102: Citation count uses chunks (citable units) not unique files - #103: Clamp max_iterations to min 1 (can't bypass via iterations=0) Pre-release quality (T2 HIGH): - #104: Add LIKE ESCAPE in all SQL fallback paths - #105: Gemini safety block returns "" (was bypassing stack) - #106: Cap reasoning model budget at 128000 - #107: Handle non-numeric temperature/max_tokens gracefully - #108: Fix clarification history duplication Pre-release quality (T2 MEDIUM): - #109: Anthropic temperature clamp to 1.0 - #110: SQL query 10-second timeout via progress handler - #111: Rich markup escape for user/LLM content - #112: All 6 readers wrapped in try/except (corrupt files don't abort) - #113: Collection cache invalidation after re-ingestion - #114: Web UI message history capped at 200 - #115: Setup wizard confi…f95cdb7 -
fix: pre-release audit round 12 — 33 bugs fixed across all tiers
Tier 1 (ship-blockers): - README/verifier layer count corrected to 7-layer/10-point - SQL keyword regex now strips quoted strings before checking - validate_citations counts unique sources, extracts from body only - Provider-specific error messages for all 3 LLM backends - Missing config error handling in ingest.py entry point Tier 2 (quality): - SQL injection: alphanumeric validation on interpolated values - LIKE wildcard escaping with ESCAPE clause - Fallback builds fresh keyword query instead of re-running failed SQL - NaN/NaT/inf filtering across all tabular readers - Merged docx table cells deduplicated via element identity - .env double-escaping fix in setup wizard - Verification LLM exceptions skip correction instead of triggering it - References check handles SQL and web sources - Dead pre-loop validate_citations removed - KB meta extension detection uses Path.suffix - QU prompt omits SQL fields when no schema available - Redundant collection.count() eliminated - Row padding f…fbd18c8
-
fix: clear both kb_meta.txt and kb_meta_brief.txt on every re-ingestion
Ensures stale overview files are always overwritten, both in the normal ingestion path and the no-files-found cleanup path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>b199600 -
fix: curated model lists, reasoning model token scaling, skip temp files
- Restrict each provider to 3 supported models instead of fetching all from API (OpenAI: gpt-4.1/4o/4o-mini, Anthropic: sonnet/opus/haiku, Gemini: 2.5-pro/2.5-flash/2.0-flash) - Scale up max_completion_tokens 4x for OpenAI reasoning models (o1/o3/o4) since reasoning tokens count against the budget - Skip ~$ temp Excel files during ingestion - Log LLM errors in codebook description generation for debugging Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>112b4f4 -
fix: try alternate TEXT columns before word-level fuzzy matching
When phrase-level fuzzy fails on the original column (e.g. Country), now tries phrase-level LIKE on other TEXT columns in the same table before falling back to word-level fuzzy. This fixes South Korea queries returning 98 rows (both Koreas via LIKE '%Korea%') instead of 49 rows (just South Korea via Country_OLD LIKE '%South Korea%'). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>b71f629 -
fix: prevent over-refusal on SQL results with N/A values
System prompt now explicitly tells the LLM that N/A values in dataset rows are normal (data not collected) and should not trigger a refusal. Report available data and note which fields are missing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>5ccab87 -
feat: brief KB overview for system prompt + original query cross-check
- System prompt now uses a concise 3-5 sentence KB overview instead of the full detailed listing, saving tokens for actual context - QU prompt still gets the full detailed overview for routing decisions - Response LLM now sees the original raw input alongside the reformulated display_query so it can cross-check intent if QU misunderstood Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>c23d859 -
fix: add word-level fuzzy SQL matching for country name variants
Country names like Korea, Republic of do not contain South Korea as a substring, so phrase-level LIKE fails. Word-level fuzzy extracts significant content words (dropping directional/geopolitical qualifiers) and matches individually: WHERE Country LIKE %Korea%. Three-step strategy: exact -> phrase fuzzy -> word-level fuzzy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>d4a1a18 -
fix: SQL fuzzy matching fallback for country names with alternate forms
Exact match (=) tried first; if 0 rows, auto-retries with LIKE '%...%'. Match type (exact/fuzzy) transparently reported in UI source summaries. Fixes queries like "South Korea" matching "South Korea (Republic of Korea)". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>6b689a5 -
feat: LLM-generated welcome summary for knowledge base contents
Replace raw KB overview on welcome page with a concise, friendly LLM-generated summary that highlights available topics, data volume, and suggests example questions. Falls back to truncated raw text if LLM call fails. Web UI caches summary in session state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>7e9f52f -
fix: pre-release audit round 9 — anti-hallucination hardening + error handling
CRITICAL: Correction prompt now includes previous response for targeted fixing instead of blind regeneration (AH-06). HIGH fixes: - Add deterministic citation audit Layer 4.5 (AH-12) - Strengthen verification to 10-point checklist with exact-evidence requirement (AH-07) - Warn when verification disabled or max_iterations=0 (AH-08) - Fix Gemini NameError crash in ValueError handler (ERR-1) - Add error handling to OpenAI/Anthropic with sanitized messages (ERR-2) - Clear stale data when knowledge_base/ is empty (BUG-P1) MEDIUM fixes: - Sanitize Gemini exception messages to prevent API key leaks (SEC-1) - Add config.yaml to .gitignore (SEC-2) - Detect Gemini error strings in verifier guard - Recompute citation warnings each verification iteration 174/174 tests passing. Bug fix log updated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>91410f8 -
fix: strip trailing semicolons from LLM-generated SQL and add SQL-route fallback
Two bugs prevented SQL retrieval from working: 1. LLMs append trailing semicolons to SQL (~90%% of the time). _validate_sql() rejected these as potential injection attacks. Fix: rstrip(';') before validation (internal semicolons still blocked). 2. When route=sql and the LLM SQL query failed, the keyword-based SQL fallback never triggered (condition excluded route=sql). Fix: expanded fallback to build fresh keyword query for route=sql. Verified end-to-end: China PTS scores now returns 49 rows (was 0). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>f97b9fe -
fix: Round 8 audit — 15 bugs fixed across 10 files (1 CRITICAL, 7 HIGH, 3 MEDIUM, 4 LOW)
Security fixes: - CRITICAL: execute comment-stripped SQL query (not original) to prevent injection bypass - HIGH: iterative comment stripping to handle nested comment attacks - HIGH: expand dangerous SQL keyword blocklist from 11 to 23 entries - HIGH: data loss prevention — deferred clear only on first successful embed Robustness fixes: - HIGH: parse_verification_result(None) crash guard - HIGH: try/except on all verification loop generate() calls - HIGH: empty rows guard in Excel reader - MEDIUM: strict boolean normalization for verification pass/fail - MEDIUM: R-style "na" added to null string detection - MEDIUM: broad exception handling for Gemini API errors Minor fixes: - LOW: distinct error message for empty LLM response vs no sources - LOW: bounds check on setup wizard model selection - LOW: route/sql_query keys in CLI and web fallback dicts - LOW: SQL fallback extended to route="both" Cross-checked by 2 verification agents — all fixes confirmed correct. 165/165 tests passing,…9093d8f -
fix: 10 bugs (4 HIGH + 6 MEDIUM) from comprehensive codebase audit
HIGH fixes: - H1: Gemini blocked-response detection in verifier (safety filter short-circuit) - H2: Config load crash guard in app_web.py (st.stop instead of traceback) - H3: Brace-escape user text in kb_meta.py prompts (prevent KeyError) - H4: Web UI clarification state tracking (pending_clarification_question) MEDIUM fixes: - M1: Preserve leading zeros as TEXT in sql_ingest type inference - M2: Deferred clearing in ingest.py prevents data loss on total failure - M3: Strip markdown fences from LLM-generated SQL in sql_retriever - M4: max_iterations=0 guard in verifier (skip verification, do not refuse) - M5: Add clarification QA to conversation history for pronoun resolution - M6: Remove hardcoded knowledge_base/ prefix in retriever source paths Also adds CLAUDE.md, docs/plans/, full test suite (162 tests, 17 files), and updates WORKLOG.md with audit results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1330e5c -
fix: 6-agent debug audit — 8 bugs fixed across codebase
Multi-agent systematic audit found and fixed: HIGH: - Empty model="" overrode provider defaults, causing API errors when no model configured (llm/__init__.py + all 3 providers) - Vector-to-SQL fallback was dead code — QU layer now preserves sql_query regardless of route, and prompt asks LLM to generate fallback sql_query - SQL validation strengthened with keyword blocklist (INSERT, DELETE, DROP, ALTER, CREATE, ATTACH, DETACH, PRAGMA, LOAD_EXTENSION) — first layer of two-layer SQL injection defense MEDIUM: - Verification prompt no longer leaks internal chunk ID naming (CHUNK-LOCAL, CHUNK-SQL) into correction loop — uses user-facing language instead - config_loader now gives friendly FileNotFoundError directing user to run setup.py, instead of raw traceback - config.yaml opened with explicit encoding="utf-8" for cross-platform safety - OpenAI model filter narrowed from startswith("o") to startswith("o1","o3","o4") 153 tests pass (152 existing + 1 new SQL validation test). …106354e -
fix: harden route parsing, column dedup, and column name access
- Normalize QU route output (strip/lowercase) before validation - Fix column name deduplication to handle suffix collisions (e.g., 'Score_A', 'Score_A', 'Score_A_2' no longer produces duplicates) - Use defensive .get() for column name access in SQL result formatting Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>a8fd301 -
fix: 7 bugs from multi-agent debug review of SQL layer
- Column name deduplication after sanitization (Score-A/Score_A collision) - _safe_str() preserves None in Stata/SPSS/R data loaders - Reject inf/Infinity in column type inference - Guard against n=1 in _get_sample_values (ZeroDivisionError) - NULL values render as "N/A" in SQL context (not "None") - Defensive .get() in build_schema_summary for malformed schema - Backtick-quoted table names in _extract_table_from_query regex Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>d6a01c7 -
fix: 4 bugs found during comprehensive code review
- Sort sample values numerically when all values are numeric (was lexicographic) - Handle CSV BOM (utf-8-sig) so Excel-exported CSVs do not corrupt first header - Wrap file_path.relative_to() in try/except to prevent crash on edge-case paths - Fix schema summary colon placement (was appended after description instead of header) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>86e20a0 -
feat: add LLM-powered column descriptions with codebook detection
During SQL ingestion, each table columns are now described by the LLM: 1. Search same directory for codebook/documentation files (PDF, DOCX, TXT, MD) 2. If codebook found, pass its text + column metadata to LLM for descriptions 3. If no codebook, LLM infers column meanings from names, types, samples 4. Descriptions stored in sql_schemas.json alongside existing column metadata Column descriptions are always visible to the chatbot: - build_schema_summary() includes descriptions in the QU prompt - format_sql_results_as_context() includes descriptions with SQL results - Graceful degradation: LLM failure is non-fatal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>3d1d5b4 -
fix: include sample values in SQL schema summary for better query generation
The LLM was generating SQL queries with wrong column values (e.g., guessing country name format) because the schema summary only showed column names and types. Now includes up to 3 sample values per column so the LLM can see actual data format (e.g., Country: "China", "United States", "Brazil"). Before: - table (N rows): Country (TEXT), Year (INTEGER) After: - table (N rows, from PTS/data.xlsx): Country (TEXT) e.g. "China", "United States" Year (INTEGER) e.g. "1976", "2000" This fixes the issue where asking "PTS scores for China" would route to SQL but generate queries that returned no results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>353f65a -
fix: harden SQL ingest connection handling and brace-escape all prompt parameters
- Extract _ingest_tables() helper in sql_ingest.py to ensure SQLite connection is always closed via try/finally - Apply _escape_braces() to bot_name and domain in build_prompt() and build_query_understanding_prompt() to prevent KeyError on user-supplied text containing curly braces Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>3a0fe98
-
fix: fallback to KB meta overview when vector search returns no results
When all chunks exceed the distance threshold, the retriever now fetches the KB meta overview chunk directly as a fallback. This fixes meta-questions like "do you have any dataset?" returning empty results when the embedding similarity didn't match closely enough. Also adds a system prompt instruction to use the KB overview to describe what IS available when it's the only local source. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>2317f6c -
fix: harden source display, subdirectory paths, and chunk ID uniqueness
- app_cli: _format_sources now includes SQL results in /sources output - ingest: source_name uses full relative path (preserves subdirectories) - ingest: chunk IDs use full path prefix to prevent collisions - kb_meta: import _escape_braces from prompts instead of duplicating Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>01b9f34 -
docs: update README with KB self-awareness section and fix missing connection note
- Add "KB Self-Awareness: The Meta Overview" section explaining how the chatbot knows what it knows and can answer meta-questions - Update "What This Does", "How It Works", key design principles, and Advantages to highlight KB awareness as a core capability - Add connection note to deterministic fallback overview for multi-dataset KBs (was specified in design but missing from implementation) - Add test assertion for connection note Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>864852c -
feat: add KB meta overview for meta-question answering and LLM awareness
Generate an LLM-powered high-level summary of the knowledge base at ingestion time. The overview is stored as a ChromaDB chunk (enabling vector search for meta-questions like "what data do you have?") and injected into QU and system prompts (giving the LLM full KB awareness for routing and contextualized answers). New: src/kb_meta.py, tests/test_kb_meta.py (20 tests) Modified: ingest.py, prompts.py, query_engine.py, verifier.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>8f35c1b -
fix: improve clarification context and meta-question routing
- Include clarification Q&A in combined query string so the QU layer gets full context (app_cli.py + app_web.py) - Route meta-questions about data availability to vector search, not SQL (src/prompts.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>c014da5 -
fix: prevent NameError when QU disabled and fix connection leak
- Add route="vector" and sql_query=None defaults before the `if qu_enabled:` block in both app_cli.py and app_web.py, preventing NameError when query understanding is disabled. - Wrap sqlite3 connection in try/finally in sql_retriever.py to ensure conn.close() runs even if execute/fetchmany raises. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>39c2d11 -
feat: integrate SQL ingestion into the main ingest pipeline
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>3653d68 -
feat: add SQL routing, fallback, and context merging to retriever
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>7758af3 -
feat: add SQL schema loading and route/sql_query parsing to query engine
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>c65382c