-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: add nomic-embed-code support with model-specific score thresholds and query prefixes (#5027) #5036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
fix: add nomic-embed-code support with model-specific score thresholds and query prefixes (#5027) #5036
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ export type EmbedderProvider = "openai" | "ollama" | "openai-compatible" // Add | |
|
|
||
| export interface EmbeddingModelProfile { | ||
| dimension: number | ||
| scoreThreshold?: number // Model-specific minimum score threshold for semantic search | ||
| queryPrefix?: string // Optional prefix required by the model for queries | ||
| // Add other model-specific properties if needed, e.g., context window size | ||
| } | ||
|
|
||
|
|
@@ -18,21 +20,31 @@ export type EmbeddingModelProfiles = { | |
| // Example profiles - expand this list as needed | ||
| export const EMBEDDING_MODEL_PROFILES: EmbeddingModelProfiles = { | ||
| openai: { | ||
| "text-embedding-3-small": { dimension: 1536 }, | ||
| "text-embedding-3-large": { dimension: 3072 }, | ||
| "text-embedding-ada-002": { dimension: 1536 }, | ||
| "text-embedding-3-small": { dimension: 1536, scoreThreshold: 0.4 }, | ||
| "text-embedding-3-large": { dimension: 3072, scoreThreshold: 0.4 }, | ||
| "text-embedding-ada-002": { dimension: 1536, scoreThreshold: 0.4 }, | ||
| }, | ||
| ollama: { | ||
| "nomic-embed-text": { dimension: 768 }, | ||
| "mxbai-embed-large": { dimension: 1024 }, | ||
| "all-minilm": { dimension: 384 }, | ||
| "nomic-embed-text": { dimension: 768, scoreThreshold: 0.4 }, | ||
| "nomic-embed-code": { | ||
| dimension: 3584, | ||
| scoreThreshold: 0.15, | ||
| queryPrefix: "Represent this query for searching relevant code: ", | ||
| }, | ||
| "mxbai-embed-large": { dimension: 1024, scoreThreshold: 0.4 }, | ||
| "all-minilm": { dimension: 384, scoreThreshold: 0.4 }, | ||
| // Add default Ollama model if applicable, e.g.: | ||
| // 'default': { dimension: 768 } // Assuming a default dimension | ||
| }, | ||
| "openai-compatible": { | ||
| "text-embedding-3-small": { dimension: 1536 }, | ||
| "text-embedding-3-large": { dimension: 3072 }, | ||
| "text-embedding-ada-002": { dimension: 1536 }, | ||
| "text-embedding-3-small": { dimension: 1536, scoreThreshold: 0.4 }, | ||
| "text-embedding-3-large": { dimension: 3072, scoreThreshold: 0.4 }, | ||
| "text-embedding-ada-002": { dimension: 1536, scoreThreshold: 0.4 }, | ||
|
Comment on lines
+23
to
+42
|
||
| "nomic-embed-code": { | ||
| dimension: 3584, | ||
| scoreThreshold: 0.15, | ||
| queryPrefix: "Represent this query for searching relevant code: ", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -59,6 +71,38 @@ export function getModelDimension(provider: EmbedderProvider, modelId: string): | |
| return modelProfile.dimension | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the score threshold for a given provider and model ID. | ||
| * @param provider The embedder provider (e.g., "openai"). | ||
| * @param modelId The specific model ID (e.g., "text-embedding-3-small"). | ||
| * @returns The score threshold or undefined if the model is not found. | ||
| */ | ||
| export function getModelScoreThreshold(provider: EmbedderProvider, modelId: string): number | undefined { | ||
| const providerProfiles = EMBEDDING_MODEL_PROFILES[provider] | ||
| if (!providerProfiles) { | ||
| return undefined | ||
| } | ||
|
|
||
| const modelProfile = providerProfiles[modelId] | ||
| return modelProfile?.scoreThreshold | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the query prefix for a given provider and model ID. | ||
| * @param provider The embedder provider (e.g., "openai"). | ||
| * @param modelId The specific model ID (e.g., "nomic-embed-code"). | ||
| * @returns The query prefix or undefined if the model doesn't require one. | ||
| */ | ||
| export function getModelQueryPrefix(provider: EmbedderProvider, modelId: string): string | undefined { | ||
| const providerProfiles = EMBEDDING_MODEL_PROFILES[provider] | ||
| if (!providerProfiles) { | ||
| return undefined | ||
| } | ||
|
|
||
| const modelProfile = providerProfiles[modelId] | ||
| return modelProfile?.queryPrefix | ||
| } | ||
|
|
||
| /** | ||
| * Gets the default *specific* embedding model ID based on the provider. | ||
| * Does not include the provider prefix. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract this query prefix literal into a constant (e.g., NOMINC_EMBED_CODE_PREFIX) to reduce duplication and improve readability.