Skip to content

fix(embedding): add dimension resolution for Ollama embedding provider#915

Merged
qin-ctx merged 1 commit intovolcengine:mainfrom
JasonOA888:fix/ollama-embedding-dimension
Mar 24, 2026
Merged

fix(embedding): add dimension resolution for Ollama embedding provider#915
qin-ctx merged 1 commit intovolcengine:mainfrom
JasonOA888:fix/ollama-embedding-dimension

Conversation

@JasonOA888
Copy link
Copy Markdown
Contributor

Summary

Fixes #865 (Bug 1)

Problem

When using Ollama as embedding provider with models like nomic-embed-text, get_effective_dimension() would fallback to 2048 (default). This caused:

  1. Collection created with Dim: 2048
  2. Ollama returns 768-dim vectors
  3. Qdrant similarity scores become inf
  4. JSON serialization fails: Out of range float values are not JSON compliant: inf

Solution

Added Ollama-specific dimension resolution in get_effective_dimension():

  • Known Ollama models return their correct dimension
  • Unknown models raise clear error requiring explicit dimension config
ollama_model_dimensions = {
    "nomic-embed-text": 768,
    "mxbai-embed-large": 1024,
    "all-minilm": 384,
    "snowflake-arctic-embed": 1024,
    # ...
}

Testing

# ov.conf
embedding:
  dense:
    provider: ollama
    model: nomic-embed-text
    api_base: http://localhost:11434/v1
  • Before: inf similarity scores, JSON error
  • After: Collection created with 768-dim, search works correctly

When using Ollama as embedding provider, get_effective_dimension() would
fallback to 2048 (default) which caused inf similarity scores when the
actual model dimension differs (e.g., nomic-embed-text is 768-dim).

This fix:
- Adds known Ollama model dimensions (nomic, mxbai, all-minilm, etc.)
- Raises clear error for unknown models requiring explicit dimension
- Prevents collection dimension mismatch

Fixes volcengine#865 (Bug 1)
@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@qin-ctx qin-ctx merged commit 605431d into volcengine:main Mar 24, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 24, 2026
zeattacker pushed a commit to zeattacker/OpenViking that referenced this pull request Mar 25, 2026
volcengine#915)

Cherry-pick from upstream 605431d

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Ollama provider: inf similarity scores + VLM api_base not forwarded to OpenAI client

2 participants