Skip to content

feat(embeddings): native Ollama embedding provider - #146

Open
PatrickSys wants to merge 1 commit into
masterfrom
cursor/native-ollama-provider-cdd7
Open

PatrickSys wants to merge 1 commit into
masterfrom
cursor/native-ollama-provider-cdd7

Conversation

@PatrickSys

Copy link
Copy Markdown
Owner

Implements #71: EMBEDDING_PROVIDER=ollama uses a new OllamaEmbeddingProvider (/api/embed, default OLLAMA_HOST=http://localhost:11434, default model nomic-embed-text) instead of falling back to Transformers.js.

  • Skips @huggingface/transformers when provider is ollama; dimension hints for LanceDB via known model map + optional OLLAMA_EMBEDDING_DIMENSIONS
  • Config helpers in types.ts include OPENAI_BASE_URL wiring (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 work
  • README Privacy section + docs/capabilities.md; Vitest HTTP mocks in tests/ollama-embeddings.test.ts and tests/embedding-config-env.test.ts

Fixes #71

Open in Web Open in Cursor 

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T22:29:03.947336Z 333f520 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/embeddings/index.ts
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread src/embeddings/ollama.ts
return parsed;
}
}
return 768;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[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.

Findings

  1. P1 Custom models cannot refresh ▶
  2. P1 Search calls the wrong server ▶
  3. P2 Stuck requests stall indexing ▶

Summary

Adds native Ollama embeddings through /api/embed, with provider-specific defaults, model-size hints, HTTP mocks, and setup documentation.

  • Ollama now creates embeddings for indexing and semantic search.
  • Embedding settings now choose provider-specific models and API hosts.

Diagram

sequenceDiagram
  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
Loading

Reviews (1) · Last reviewed commit: "feat(embeddings): add native Ollama embe..." · Reviewed by Greptile

Comment thread src/embeddings/index.ts
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Custom models cannot refresh

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

Comment thread src/embeddings/types.ts
maxRetries: 3,
apiKey: process.env.OPENAI_API_KEY
apiKey: process.env.OPENAI_API_KEY,
apiEndpoint: resolveDefaultApiEndpoint(defaultProvider)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Search calls the wrong server

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.

Comment thread src/embeddings/ollama.ts
Comment on lines +109 to +116
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
})
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Stuck requests stall indexing

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!

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.

feat: implement native Ollama embedding provider

2 participants