Skip to content

Conversation

@sahilds1
Copy link
Collaborator

@sahilds1 sahilds1 commented Nov 20, 2025

Add Semantic Search Usage Tracking

Overview

Implements telemetry for semantic search operations by introducing a new SemanticSearchUsage model that captures performance metrics and search statistics without impacting the main search workflow.

Benefits

  • Performance insights: Identify slow encoding or database query operations
  • Usage analytics: Track search patterns by user and over time
  • Result quality: Monitor distance distributions to assess embedding model effectiveness
  • Zero-impact: Failures in telemetry collection don't affect user-facing search results

Key Implementation Details

1. Unauthenticated User Support

  • User field includes explicit documentation:
    help_text="User who performed the search (null for unauthenticated users)"
  • Service logic: user=user if (user and user.is_authenticated) else None
  • Enables tracking of anonymous search patterns while maintaining data integrity

2. Cascade Deletion

  • User relationship configured with on_delete=models.CASCADE
  • Rationale: Search usage records are considered disposable when the associated user account is deleted
  • Prevents orphaned telemetry data accumulation

3. Resilient Telemetry

  • Database writes wrapped in try/except block to ensure telemetry failures never break search functionality
  • Error logging for debugging: "Failed to create semantic search usage database record: {e}"
  • Records created even for zero-result searches (with num_results_returned=0 and None distance stats)
  • Warning logged when searches return no results for operational visibility

@sahilds1 sahilds1 self-assigned this Nov 20, 2025
@sahilds1 sahilds1 changed the title Add performance tracking to embedding search [WIP] [#380] Track chatbot costs and performance Nov 20, 2025
@sahilds1 sahilds1 marked this pull request as ready for review December 17, 2025 20:37
@sahilds1 sahilds1 marked this pull request as draft December 17, 2025 20:59
@sahilds1 sahilds1 changed the title [WIP] [#380] Track chatbot costs and performance [#380] Track chatbot costs and performance Dec 18, 2025
@sahilds1 sahilds1 changed the title [#380] Track chatbot costs and performance [#380] Track chatbot semantic search costs and performance Dec 18, 2025
@sahilds1 sahilds1 marked this pull request as ready for review December 19, 2025 23:38
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