Repository navigation
feat(embeddings): native Ollama embedding provider - #146
PatrickSys wants to merge 1 commit into
Conversation
Implement OllamaEmbeddingProvider using /api/embed with OLLAMA_HOST and provider-specific model defaults. Wire getEmbeddingProvider, dimension detection, and skip Transformers runtime for ollama. Includes OPENAI_BASE_URL config compatible with PR #145, docs, and HTTP-mocked tests.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 333f5203da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| console.warn('Ollama provider not yet implemented, falling back to Transformers.js'); | ||
| const { OllamaEmbeddingProvider } = await import('./ollama.js'); | ||
| const provider = new OllamaEmbeddingProvider( | ||
| mergedConfig.model || DEFAULT_OLLAMA_MODEL, |
There was a problem hiding this comment.
Resolve the default model from the effective provider
When Ollama is selected through project configuration or getEmbeddingProvider({ provider: 'ollama' }), without setting EMBEDDING_PROVIDER, the merged configuration still contains the nonempty Transformers default Xenova/bge-small-en-v1.5. Consequently, this fallback never selects nomic-embed-text, and initialization requests the wrong model from Ollama, failing even when the documented default model is installed. Resolve provider-specific defaults after applying the explicit provider configuration; the indexer's configuration merge needs the same treatment.
Useful? React with 👍 / 👎.
| return parsed; | ||
| } | ||
| } | ||
| return 768; |
There was a problem hiding this comment.
Use discovered dimensions for incremental validation
For an Ollama model outside the hardcoded map that returns vectors other than 768 dimensions, a full build succeeds because embedBatch() discovers the actual vector length. However, the next incremental build calls getConfiguredDimensions(), which independently returns this 768 fallback unless OLLAMA_EMBEDDING_DIMENSIONS is set. LanceDBStorageProvider.initialize() then rejects the valid existing table with a dimension-mismatch error. Use the discovered or persisted dimensions for incremental validation rather than treating an unknown model's guessed size as authoritative.
Useful? React with 👍 / 👎.
[Medium impact] The PR changes the embedding route used by indexing and semantic search. Fix custom-model refresh and provider-specific endpoint defaults before merging. FindingsSummaryAdds native Ollama embeddings through
DiagramsequenceDiagram
participant Caller as Indexer or search
participant Factory as Embedding factory
participant Ollama as Ollama server
participant Store as LanceDB
Caller->>Factory: Resolve provider and model
Factory->>Ollama: POST /api/show
Ollama-->>Factory: Model details
Factory-->>Caller: Ollama provider
Caller->>Ollama: POST /api/embed
Ollama-->>Caller: Vectors
Caller->>Store: Store or search vectors
Reviews (1) · Last reviewed commit: "feat(embeddings): add native Ollama embe..." · Reviewed by Greptile |
| config.provider ?? parseEmbeddingProviderName(process.env.EMBEDDING_PROVIDER) ?? 'transformers'; | ||
| const model = config.model ?? process.env.EMBEDDING_MODEL ?? DEFAULT_MODEL; | ||
| if (provider === 'openai') return model.includes('large') ? 3072 : 1536; // text-embedding-3-large: 3072, all others: 1536 | ||
| if (provider === 'ollama') return getOllamaModelDimensions(model); |
There was a problem hiding this comment.
getConfiguredDimensions keeps using a fixed guess after Ollama returns the actual vector size. If a custom model returns 1024 values and OLLAMA_EMBEDDING_DIMENSIONS is unset, a full build succeeds. A later incremental refresh compares those stored vectors against 768 and throws IndexCorruptedError.
Use the resolved vector size for the incremental check, or require an explicit size before building an unknown model.
Knowledge Base Used: Index storage and integrity
| maxRetries: 3, | ||
| apiKey: process.env.OPENAI_API_KEY | ||
| apiKey: process.env.OPENAI_API_KEY, | ||
| apiEndpoint: resolveDefaultApiEndpoint(defaultProvider) |
There was a problem hiding this comment.
Provider overrides inherit the endpoint chosen for the environment's provider. If an Ollama index is opened while EMBEDDING_PROVIDER=openai, search supplies the stored Ollama provider and model but retains OpenAI's default endpoint. The new Ollama branch then sends /api/show to OpenAI, so semantic search cannot start.
Resolve the default endpoint from the final provider after merging the caller's settings. Apply the same ordering to the model default.
| const response = await fetch(`${this.host}/api/embed`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| model: this.modelName, | ||
| input: texts.length === 1 ? texts[0] : texts | ||
| }) | ||
| }); |
There was a problem hiding this comment.
Neither new HTTP request has an application timeout. If Ollama stops answering while loading or running a model, indexing keeps waiting rather than reporting a useful failure.
Add a configurable deadline to both /api/show and /api/embed, with enough time for a cold model load. This is a non-blocking improvement.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Implements #71:
EMBEDDING_PROVIDER=ollamauses a newOllamaEmbeddingProvider(/api/embed, defaultOLLAMA_HOST=http://localhost:11434, default modelnomic-embed-text) instead of falling back to Transformers.js.@huggingface/transformerswhen provider isollama; dimension hints for LanceDB via known model map + optionalOLLAMA_EMBEDDING_DIMENSIONStypes.tsincludeOPENAI_BASE_URLwiring (compatible with First-run fixes: OPENAI_BASE_URL and CLI entrypoint regression test #145 /cursor/first-run-fixes-16ec) without duplicating that PR’s CLI entrypoint workdocs/capabilities.md; Vitest HTTP mocks intests/ollama-embeddings.test.tsandtests/embedding-config-env.test.tsFixes #71