Skip to content

feat: perf optimizations#846

Merged
MODSetter merged 2 commits intomainfrom
dev
Feb 28, 2026
Merged

feat: perf optimizations#846
MODSetter merged 2 commits intomainfrom
dev

Conversation

@MODSetter
Copy link
Owner

@MODSetter MODSetter commented Feb 28, 2026

Description

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR introduces performance optimizations through two main strategies: batch API endpoints for comments to eliminate N+1 query problems on the frontend, and parallel search execution with embedding reuse in the backend retrieval pipeline. The batch comments API allows fetching comments for multiple messages in a single request, while the search optimizations execute chunk and document retrievers concurrently using separate database sessions and share pre-computed query embeddings. Additional cleanup includes formatting multi-line logging statements for better readability across the codebase.

⏱️ Estimated Review Time: 30-90 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/contracts/types/chat-comments.types.ts
2 surfsense_backend/app/schemas/chat_comments.py
3 surfsense_web/lib/apis/chat-comments-api.service.ts
4 surfsense_backend/app/routes/chat_comments_routes.py
5 surfsense_backend/app/services/chat_comments_service.py
6 surfsense_web/hooks/use-comments.ts
7 surfsense_web/components/assistant-ui/thread.tsx
8 surfsense_backend/app/retriever/chunks_hybrid_search.py
9 surfsense_backend/app/retriever/documents_hybrid_search.py
10 surfsense_backend/app/services/connector_service.py
11 surfsense_backend/app/agents/new_chat/tools/knowledge_base.py
12 surfsense_backend/app/indexing_pipeline/indexing_pipeline_service.py
13 surfsense_backend/app/services/llm_router_service.py

Need help? Join our Discord

Analyze latest changes

- improved search_knowledgebase_tool
- Added new endpoint to batch-fetch comments for multiple messages, reducing the number of API calls.
- Introduced CommentBatchRequest and CommentBatchResponse schemas for handling batch requests and responses.
- Updated chat_comments_service to validate message existence and permissions before fetching comments.
- Enhanced frontend with useBatchCommentsPreload hook to optimize comment loading for assistant messages.
@vercel
Copy link

vercel bot commented Feb 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
surf-sense-frontend Building Building Preview, Comment Feb 28, 2026 1:22am

Request Review

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on 11a38a2..08829c1

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (13)

surfsense_backend/app/agents/new_chat/tools/knowledge_base.py
surfsense_backend/app/indexing_pipeline/indexing_pipeline_service.py
surfsense_backend/app/retriever/chunks_hybrid_search.py
surfsense_backend/app/retriever/documents_hybrid_search.py
surfsense_backend/app/routes/chat_comments_routes.py
surfsense_backend/app/schemas/chat_comments.py
surfsense_backend/app/services/chat_comments_service.py
surfsense_backend/app/services/connector_service.py
surfsense_backend/app/services/llm_router_service.py
surfsense_web/components/assistant-ui/thread.tsx
surfsense_web/contracts/types/chat-comments.types.ts
surfsense_web/hooks/use-comments.ts
surfsense_web/lib/apis/chat-comments-api.service.ts

@MODSetter MODSetter merged commit 4105bd0 into main Feb 28, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant