fix: skip index build when a source produces no text chunks - #320
Open
pcbeingused333 wants to merge 1 commit into
Open
fix: skip index build when a source produces no text chunks#320pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
`Retriever.index()` appends chunks and then always calls `_build_faiss()` (for `use_faiss=True`). A source that yields no text -- an empty file, a scanned/image-only PDF, a blank string -- leaves `self.chunks` empty, and `_build_faiss()` then embeds `[]` and reads `vectors.shape[1]`, raising `IndexError: tuple index out of range` (or `ValueError: need at least one array to concatenate` for the local embedder). `index()` now logs a warning and returns early when there is nothing to index, and `_query_faiss()` returns `[]` when the FAISS index was never built instead of raising from `_get_faiss()`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GtYgwYNfJ3wHrw9xrooVoB
Contributor
Author
|
The |
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.
Problem
Retriever.index()appends chunks and then always builds the backend:A source that yields no text — an empty file, a scanned/image-only PDF (
_read_pdfreturnsNone,load_documentsfilters it out), or a blank string — leavesself.chunksempty._build_faiss()then calls_embed([])and readsvectors.shape[1]:Querying before a successful index also raises from
_get_faiss()rather than returning nothing.Fix
index()logs a warning and returns early whenself.chunksis empty after chunking._query_faiss()returns[]whenself._faiss_indexisNone.No change when there is real text to index.
index([])on the BM25 path already worked and still does.Tests
Added
TestIndexWithoutChunks: FAISSindex([])andindex([" \n\n "])don't build, BM25index([])doesn't raise, andquery()before any index returns[]. The FAISS cases fail onmain.nox -t fennis green (922 passed, 7 skipped);ruff check/ruff formatclean.