Skip to content

Add BM25/TF-IDF full-text search index#272

Merged
JE-Chen merged 1 commit into
devfrom
feat/search-index
Jun 20, 2026
Merged

Add BM25/TF-IDF full-text search index#272
JE-Chen merged 1 commit into
devfrom
feat/search-index

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

fuzzy does pairwise string similarity and skill_library matches substrings alphabetically, but neither ranks a corpus of documents by relevance. This adds an inverted-index search ranked with Okapi BM25 (or TF-IDF), so flows and agents can search logs, scraped records, or knowledge snippets without a database.

  • SearchIndex(k1=1.5, b=0.75, stop_words=...)add / remove (incremental), build({id: text}), search(query, top_k=, mode="bm25"|"tfidf") → ranked SearchHit(doc_id, score), stats().
  • search_documents(docs, query, ...) — one-shot convenience.
  • tokenize(text) — the shared normalizer.

BM25 with IDF = ln(1 + (N − df + 0.5)/(df + 0.5)): a rare term out-ranks a common one, term frequency saturates (k1), long docs are normalized down (b). Deterministic (ties broken by doc_id). Pure stdlib (math+collections+re).

Five-layer wiring

  • Headless core: je_auto_control/utils/search_index/
  • Facade: re-exported from __init__.py + __all__
  • Executor: AC_search_documents{hits: [{doc_id, score}]}
  • MCP: ac_search_documents
  • Script Builder: "Full-Text Search (BM25)" under Data

Tests & docs

  • test/unit_test/headless/test_search_index_batch.py (14 tests: IDF boost, tf saturation, length normalization, tfidf mode, top_k, remove/reindex, stop-words, determinism)
  • v64 feature docs (EN + Zh) + toctree registration
  • What's-new sections in all three READMEs

Lint clean: ruff / pylint / bandit / radon (no function CC > 10).

fuzzy does pairwise similarity and skill_library matches substrings
alphabetically, but neither ranks a document corpus by relevance. Add an
inverted-index search ranked with Okapi BM25 (or TF-IDF): a rare term
out-ranks a common one, term frequency saturates, and long documents are
normalized down. Incremental add/remove, optional stop-words, deterministic.
Pure stdlib; wired through the facade, AC_search_documents executor
command, ac_search_documents MCP tool and the Script Builder.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 69 complexity · 0 duplication

Metric Results
Complexity 69
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen
JE-Chen merged commit 6f8c26d into dev Jun 20, 2026
16 checks passed
@JE-Chen
JE-Chen deleted the feat/search-index branch June 20, 2026 23:01
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant