Skip to content

[BUG] Embedding Dimension Mismatch Returns Silent Zero Similarity #92

@olddev94

Description

@olddev94

Project

vgrep

Description

The cosine_similarity() function in src/core/db.rs lines 286-289 silently returns 0.0 when comparing embeddings of different dimensions. This can happen if the embedding model is changed after indexing. All search results will show 0% similarity with no indication of the underlying problem.

Error Message

No error message - all search results silently show 0% similarity.

Debug Logs

System Information

- Bounty Version: 0.1.0
- OS: Ubuntu 24.04 LTS
- Rust: 1.75+

Screenshots

No response

Steps to Reproduce

  1. Index a codebase with the default embedding model (768 dimensions)
  2. Switch to a different embedding model with different dimensions
  3. Perform a search
  4. Observe all results show 0% or very low similarity

Expected Behavior

When embedding dimensions don't match:

  1. Log a warning about dimension mismatch
  2. Return an error or special value indicating incompatibility
  3. Suggest running vgrep index --force to reindex with current model
  4. Show clear error message to user

Actual Behavior

  1. Dimension mismatch is silently ignored
  2. All comparisons return 0.0 similarity
  3. Search results appear with 0% match scores
  4. User has no indication of the problem or how to fix it

Additional Context

This bug is particularly insidious because:

  1. The user sees search results (just with low scores)
  2. There's no error message
  3. The fix (reindexing) is not suggested
  4. Users may think the tool just doesn't work well

Common scenarios that trigger this:

  • Upgrading vgrep to a version with a different default model
  • Manually changing the embedding model in config
  • Corrupted model download resulting in wrong model being used

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingideIssues related to IDEinvalidThis doesn't seem rightvgrep

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions