fix(memory): add openrouter as recognized embedding provider
The embedding provider factory only recognized "openai" and "custom:*", causing "openrouter" to silently fall through to NoopEmbedding. This made vector/semantic search completely non-functional — memory recall fell back to BM25 keyword-only matching, with 70% of the hybrid score always returning zero. Route "openrouter" through OpenAiEmbedding with the OpenRouter API base URL (https://openrouter.ai/api/v1), which is OpenAI-compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b43e9eb325
commit
832facf5ef
1 changed files with 35 additions and 0 deletions
|
|
@ -172,6 +172,15 @@ pub fn create_embedding_provider(
|
|||
dims,
|
||||
))
|
||||
}
|
||||
"openrouter" => {
|
||||
let key = api_key.unwrap_or("");
|
||||
Box::new(OpenAiEmbedding::new(
|
||||
"https://openrouter.ai/api/v1",
|
||||
key,
|
||||
model,
|
||||
dims,
|
||||
))
|
||||
}
|
||||
name if name.starts_with("custom:") => {
|
||||
let base_url = name.strip_prefix("custom:").unwrap_or("");
|
||||
let key = api_key.unwrap_or("");
|
||||
|
|
@ -212,6 +221,18 @@ mod tests {
|
|||
assert_eq!(p.dimensions(), 1536);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn factory_openrouter() {
|
||||
let p = create_embedding_provider(
|
||||
"openrouter",
|
||||
Some("sk-or-test"),
|
||||
"openai/text-embedding-3-small",
|
||||
1536,
|
||||
);
|
||||
assert_eq!(p.name(), "openai"); // uses OpenAiEmbedding internally
|
||||
assert_eq!(p.dimensions(), 1536);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn factory_custom_url() {
|
||||
let p = create_embedding_provider("custom:http://localhost:1234", None, "model", 768);
|
||||
|
|
@ -281,6 +302,20 @@ mod tests {
|
|||
assert_eq!(p.dimensions(), 384);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn embeddings_url_openrouter() {
|
||||
let p = OpenAiEmbedding::new(
|
||||
"https://openrouter.ai/api/v1",
|
||||
"key",
|
||||
"openai/text-embedding-3-small",
|
||||
1536,
|
||||
);
|
||||
assert_eq!(
|
||||
p.embeddings_url(),
|
||||
"https://openrouter.ai/api/v1/embeddings"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn embeddings_url_standard_openai() {
|
||||
let p = OpenAiEmbedding::new("https://api.openai.com", "key", "model", 1536);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue