feat: score threshold filtering, .txt support, API key trimming#2
Open
biswajeetdev wants to merge 1 commit into
Open
feat: score threshold filtering, .txt support, API key trimming#2biswajeetdev wants to merge 1 commit into
biswajeetdev wants to merge 1 commit into
Conversation
- retrieve() now filters out chunks below MIN_SCORE=0.20 cosine similarity; without this the LLM receives irrelevant chunks when the document doesn't contain an answer, causing hallucinated or misleading responses - file uploader now accepts .txt files in addition to PDF; plain text is decoded directly instead of going through PdfReader - API key inputs now call .strip() before use — whitespace-padded keys from copy-paste were silently creating invalid clients
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.
What
Three quality-of-life fixes found while doing a thorough test pass:
Fix 1 — Low-relevance chunks passed to LLM (
rag.py)retrieve()returned allTOP_K=4chunks regardless of their cosine similarity score. When a user asks something not covered by the document, FAISS still returns the closest matches even if their scores are0.05–0.12— far below useful similarity. The LLM then generates a hallucinated answer from those irrelevant chunks instead of saying "not in the document."Added
MIN_SCORE = 0.20floor. If all retrieved chunks are below threshold,retrieve()returns[], andgenerate_answeralready handles empty retrieval gracefully with:Fix 2 —
.txtfiles not supported (app.py)The uploader accepted only
type="pdf". Plain text files (notes, logs, transcripts, Markdown exports) are a primary use case for a doc QA tool. Addedtype=["pdf", "txt"]and a branch for UTF-8 decoding via.read().decode()instead ofPdfReader.Fix 3 — Whitespace in pasted API keys causes silent failure (
app.py)Keys copied from browser often include a trailing newline or space.
make_chat_client(api_key)creates a client with the whitespace-padded key, which fails on first API call with a cryptic 401. Added.strip()immediately after eachst.text_input.Test