fix: Document deletion now properly updates the stale knowledge filter source count#1929
fix: Document deletion now properly updates the stale knowledge filter source count#1929Vchen7629 wants to merge 10 commits into
Conversation
…r from crashing rest
…private helper to keep search_knowledge_filters method focused
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds an ChangesActive source count for knowledge filters
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/knowledge_filter_service.py`:
- Around line 68-72: The zip() call that iterates over filters and
data_sources_by_filter is missing the strict=True parameter, which could allow
silent truncation bugs if the iterables have mismatched lengths during future
refactoring. Add strict=True as a parameter to the zip() function call to ensure
both iterables have matching lengths and raise a ValueError if they don't,
improving code safety and maintainability.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0f46164f-0076-4d85-9a9c-7937deea4236
📒 Files selected for processing (6)
frontend/app/api/queries/useGetFiltersSearchQuery.tsfrontend/components/knowledge-filter-list.tsxfrontend/components/knowledge-filter-panel.tsxsrc/services/knowledge_filter_service.pysrc/utils/opensearch_queries.pytests/unit/test_knowledge_filter_service.py
Summary
Fixes #1254 . Knowledge filter containing specific documents used to show stale source counts even though the document was deleted and would show inflated counts if more sources are added even after the page was refreshed. This is because the source count was computed from query_data.filters.data_sources, a saved snapshot of filenames that's never pruned when a document is deleted.
Demo (Before)
screen-capture.5.webm
Demo (After)
screen-capture.3.webm
Changes
search_knowledge_filtersnow computesactive_source_countper filter by checking which of itsdata_sourcesfilenames still have indexed documents (one batched OpenSearch query via the admin client, so the count is consistent for every viewer of a shared filter)build_existing_filenames_agg_bodyhelper inopensearch_queries.pyknowledge-filter-list.tsxbadge now usesactive_source_count, falling back to the old.lengthif absentknowledge-filter-panel.tsxsource dropdown now filters its selected sources against the currently-active sources before display, so its count matches toosearch_knowledge_filtersSummary by CodeRabbit