Add BM25/TF-IDF full-text search index#272
Merged
Merged
Conversation
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.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 69 |
| Duplication | 0 |
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
fuzzydoes pairwise string similarity andskill_librarymatches 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")→ rankedSearchHit(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 bydoc_id). Pure stdlib (math+collections+re).Five-layer wiring
je_auto_control/utils/search_index/__init__.py+__all__AC_search_documents→{hits: [{doc_id, score}]}ac_search_documentsTests & 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)Lint clean: ruff / pylint / bandit / radon (no function CC > 10).