Commit Graph
15 Commits
Author SHA1 Message Date
Richie 0d347e20a7 refactor(ebook-search): simplify search and phrase matching 2026-07-16 13:09:34 -04:00
Richie ed1ea4546a perf(ebook-search): run phrase detection in parallel with retrieval
Move protected phrase detection into the retrieval gather so it runs
concurrently with vector and BM25 candidates instead of sequentially
before them. Make the search API accept real bool form fields for
rerank/phrase_matching, gate phrase matching on both the request and
config kill switch, and reflow log f-strings for readability.
2026-07-16 13:09:34 -04:00
Richie 49b93c79f6 Refactor logging statements to use f-strings for improved readability and consistency across the codebase. This change enhances the clarity of log messages by directly embedding variable values, making it easier to trace and debug application behavior. 2026-07-16 13:09:34 -04:00
Richie 5925aa301d fix(protected-phrases): isolate phrase generation per book
Run full-book candidate generation inside worker-owned sessions so each book commits independently during backfills. Abort recalculation when a book has no indexed chapters to preserve existing phrase data, and update admin/UI tests for the new generation flow.
2026-07-16 13:09:34 -04:00
Richie 5bff9e82fc refactor(ebook): remove spaCy-ner attributes from PhraseCandidate and related functions 2026-07-16 13:09:34 -04:00
Richie 82fae3874b feat(ebook): add additional tokens to junk tokens configuration 2026-07-16 13:09:34 -04:00
Richie 1f5e527cbc feat(ebook): migrate to async DB/HTTP and parallelize phrase pipeline
Convert the ebook-search web app to async end to end and add concurrency
to the protected-phrase extraction and judging pipeline so large books no
longer block the event loop or the UI.

ORM / infra:
- Add get_async_postgres_engine and factor shared URL/connect_args building
  into build_postgres_url (reused by the sync and async engine builders)
- Add async FastAPI session helpers (get_async_db, AsyncDbSession) with
  expire_on_commit=False to avoid implicit IO under asyncio

App:
- Use AsyncEngine/AsyncSession throughout routes, search, ingest, embeddings,
  answer, rerank and LLM calls; convert handlers to async
- Share a single httpx.AsyncClient in app state for LLM requests; size the
  connection pool for concurrent phrase-judging workers
- Add judge_tasks: run per-book judging as tracked background tasks so a
  book already being judged isn't double-queued

Protected phrases:
- Add a process pool (pool.py) and worker-count config
  (extraction/judge book/phrase workers) to parallelize candidate generation
  and judging
- Split admin actions into all/missing variants for generation and judging

Config:
- Add protected_phrase_extraction_workers, phrase_judge_book_workers,
  phrase_judge_phrase_workers
2026-07-16 13:09:34 -04:00
Richie 9bc0d67962 feat(extraction): add cached YAKE extractor for improved performance 2026-07-16 13:09:34 -04:00
Richie d6d90489db feat(ebook): add junk tokens for improved phrase matching 2026-07-16 13:09:34 -04:00
Richie 7b97f31fec Add models and database persistence for protected phrase extraction
- Introduced dataclasses for phrase candidates, judgments, and matches in `models.py`.
- Implemented database operations for candidate and protected phrases in `store.py`, including loading, saving, and deleting phrases.
- Enhanced text normalization functions in `text_normalization.py` with detailed docstrings.
- Refactored search functionality to utilize new models and methods for detecting protected phrases.
2026-07-16 13:09:34 -04:00
Richie 6284d72af3 refactor(protected-phrases): extract config and text normalization helpers 2026-07-16 13:09:34 -04:00
Richie 37d0ae487a feat(ebook): update protected phrases with additional tokens and phrases 2026-07-16 13:09:34 -04:00
Richie ac54159496 feat(ebook): enhance phrase judgment logging with failure tracking 2026-07-16 13:09:34 -04:00
Richie 3cf50c860e feat(ebook): implement phrase matching functionality and UI enhancements 2026-07-16 13:09:34 -04:00
Richie 2427ef05a2 feat(ebook): add protected phrase extraction library with config-driven tuning
Refactor protected phrase handling from a single module into a
python/ebook_search/protected_phrases package covering extraction,
storage, and runtime matching. Phrase filtering is now data-driven via
bundled TOML files: ignored_phrases, bad_starts, bad_ends, and
most_common_words.

Add phrase-tuning settings to EbookSearchConfig so candidate generation,
scoring, LLM judging, and matching are configurable rather than hardcoded:
token bounds, entity token limit, raw n-gram min count, frequency and
chapter-spread score thresholds, candidate/LLM/target caps, confidence
threshold, nesting defaults, and the phrase hit boost.
2026-07-16 13:09:34 -04:00