Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
69dbc8e
Normalize Unicode lexical matches and keep ANN widening inside the sh…
wshlavacek Dec 1, 2026
b701166
Preserve mixed-script acronyms and widen past duplicate ANN windows
wshlavacek Dec 1, 2026
63e8e33
Stop widening at the shortlist cap and probe SQLite functions directly
wshlavacek Dec 1, 2026
1ae61f2
Recover technical terms at script boundaries and honor SQLite authori…
wshlavacek Dec 1, 2026
a25c5ed
Preserve Greek identifiers in surrounding prose and handle busy lexic…
wshlavacek Dec 1, 2026
94d3a63
Prefer the query subject over measurements and defer unused ANN lookups
wshlavacek Dec 1, 2026
fba040a
Keep numbered scientific identifiers distinct from measurement units
wshlavacek Dec 1, 2026
dd6e956
Recognize numeric powers before Unicode normalization flattens exponents
wshlavacek Dec 1, 2026
30295c3
Preserve numbered identifiers followed by superscript citations
wshlavacek Dec 1, 2026
70ffcb7
Remove superscript citation lists before extracting lexical terms
wshlavacek Dec 1, 2026
43059f5
Keep query subjects searchable beside ambiguous superscripts
wshlavacek Dec 1, 2026
59c449c
Rank technical terms across spellings and preserve alphabetic footnot…
wshlavacek Dec 1, 2026
4b5da93
Distinguish numeric powers from literal counts and internal identifie…
wshlavacek Dec 1, 2026
1fd067e
Preserve internal and leading isotope masses in chemical formulas
wshlavacek Dec 1, 2026
ff90655
Recognize leading table footnotes without broadening isotope queries
wshlavacek Dec 1, 2026
e175003
Preserve query subjects after leading table notes
wshlavacek Dec 1, 2026
26d3d61
Check isotope notation before attaching leading notes to identifiers
wshlavacek Dec 1, 2026
96b3f4c
Retain all isotope labels when matching named compounds and tracers
wshlavacek Dec 1, 2026
ad098fe
Resolve ambiguous superscript acronyms within the active search scope
wshlavacek Dec 1, 2026
7ac28a7
Preserve public acronym readings and match raised masses inside molec…
wshlavacek Dec 1, 2026
80a25db
Keep normalized query terms stable across serialization and caching
wshlavacek Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ internal versions are summarized under 0.3.33.
## [Unreleased]

### Fixed
- Keyword search now matches Unicode forms such as `fibrosis`, `CD4`, and `marker²` in existing indexes. Applications executing `sqlite_norm_expr()` on their own SQLite connections can call `litkit.retrieval.register_search_normalizer(conn)` once. LitKit handles registration for its own searches. (#20)
- Capped Stage-2 searches keep newly fetched chunks inside the paper shortlist. Sparse-shortlist fallback and explicit global lexical searches can still return other papers. (#25)
- Corpus manifests accept dotted shard names without a tar extension. The CLI reports entries it cannot resolve. (#19)
- Archive scans release processed headers. Parallel parsing keeps a bounded window and continues in order after empty articles. Compressed archives can contain rootless XML members without stopping the build. (#12, #24)
- IVF-PQ training saves a flat chunk index when the corpus has no training text. Builds also recognize untrained indexes created by `--init-indices-only` and persist the training result before updating its marker. (#11)
Expand Down
1 change: 1 addition & 0 deletions src/litkit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,7 @@ def main():
ap.add_argument(
"--allow-global-lexical",
action="store_true",
default=None,
help="Allow lexical boost without a candidate-paper filter (also respects LITKIT_ALLOW_GLOBAL_LEXICAL=1).",
)
ap.add_argument(
Expand Down
3 changes: 3 additions & 0 deletions src/litkit/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from litkit.db.normalization import register_search_normalizer

if TYPE_CHECKING:
from litkit.config.paths import WorkspacePaths

Expand Down Expand Up @@ -64,6 +66,7 @@ def connect_db(
check_same_thread=False,
isolation_level=isolation,
)
register_search_normalizer(conn)
conn.execute(f"PRAGMA busy_timeout={busy_timeout_ms}")

return conn
Expand Down
32 changes: 32 additions & 0 deletions src/litkit/db/normalization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Unicode text normalization shared by SQLite and lexical queries."""

import sqlite3
import unicodedata


def fold_search_dashes(text: str) -> str:
"""Fold dash variants after NFKC and remove discretionary hyphens."""
for dash in "‐‒–—−":
text = text.replace(dash, "-")
return text.replace("\u00ad", "")


def normalize_for_search_py(s: str) -> str:
"""Normalize compatibility characters, case and dashes for lexical matching."""
if s.isascii():
return s.lower()
return fold_search_dashes(unicodedata.normalize("NFKC", s).lower())


def _sqlite_normalize(text: str | None) -> str | None:
return None if text is None else normalize_for_search_py(text)


def register_search_normalizer(conn: sqlite3.Connection) -> None:
"""Enable sqlite_norm_expr() on a caller-supplied SQLite connection."""
conn.create_function("litkit_normalize", 1, _sqlite_normalize, deterministic=True)


def sqlite_norm_expr(field: str = "text") -> str:
"""SQL for normalized text on a LitKit connection or one with register_search_normalizer()."""
return f"litkit_normalize(CAST({field} AS TEXT))"
4 changes: 4 additions & 0 deletions src/litkit/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
from pathlib import Path

from litkit.db.normalization import register_search_normalizer

# ---------------------------------------------------------------------------
# Schema Definition (matches cli.py exactly)
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -123,6 +125,7 @@ def init_db(
db_path.parent.mkdir(parents=True, exist_ok=True)

conn = sqlite3.connect(str(db_path), isolation_level="DEFERRED", timeout=busy_timeout_ms / 1000.0)
register_search_normalizer(conn)

mode = (journal_mode or "TRUNCATE").upper()
supported = {"TRUNCATE", "WAL"}
Expand Down Expand Up @@ -179,6 +182,7 @@ def init_shard_db(
_eprint(f"[db] Producer shard {shard_id}: using {shard_path}")

conn = sqlite3.connect(str(shard_path), isolation_level="DEFERRED", timeout=busy_timeout_ms / 1000.0)
register_search_normalizer(conn)

mode = (journal_mode or "TRUNCATE").upper()
conn.execute(f"PRAGMA journal_mode={mode};")
Expand Down
2 changes: 2 additions & 0 deletions src/litkit/retrieval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
than relying on cli.py globals.
"""

from litkit.db.normalization import register_search_normalizer
from litkit.retrieval.stages import (
shortlist_papers,
search_chunks_constrained,
Expand Down Expand Up @@ -45,6 +46,7 @@
"sqlite_norm_expr",
"escape_like",
"normalize_for_search_py",
"register_search_normalizer",
"avg_chunks_for_papers",
# FAISS search
"faiss_search",
Expand Down
Loading
Loading