This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathembeddingModels.spec.ts
More file actions
95 lines (82 loc) · 3.67 KB
/
Copy pathembeddingModels.spec.ts
File metadata and controls
95 lines (82 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { describe, it, expect } from "vitest"
import {
getModelDimension,
getModelScoreThreshold,
getDefaultModelId,
EMBEDDING_MODEL_PROFILES,
} from "../embeddingModels"
describe("embeddingModels", () => {
describe("EMBEDDING_MODEL_PROFILES", () => {
it("should have gemini provider with gemini-embedding-001 model", () => {
const geminiProfiles = EMBEDDING_MODEL_PROFILES.gemini
expect(geminiProfiles).toBeDefined()
expect(geminiProfiles!["gemini-embedding-001"]).toBeDefined()
expect(geminiProfiles!["gemini-embedding-001"].dimension).toBe(3072)
})
it("should have deprecated text-embedding-004 in gemini profiles for backward compatibility", () => {
// This is critical for backward compatibility:
// Users with text-embedding-004 configured need dimension lookup to work
// even though the model is migrated to gemini-embedding-001 in GeminiEmbedder
const geminiProfiles = EMBEDDING_MODEL_PROFILES.gemini
expect(geminiProfiles).toBeDefined()
expect(geminiProfiles!["text-embedding-004"]).toBeDefined()
expect(geminiProfiles!["text-embedding-004"].dimension).toBe(3072)
})
})
describe("getModelDimension", () => {
it("should return dimension for gemini-embedding-001", () => {
const dimension = getModelDimension("gemini", "gemini-embedding-001")
expect(dimension).toBe(3072)
})
it("should return dimension for deprecated text-embedding-004", () => {
// This ensures createVectorStore() works for users with text-embedding-004 configured
// The dimension should be 3072 (matching gemini-embedding-001) because:
// 1. GeminiEmbedder migrates text-embedding-004 to gemini-embedding-001
// 2. gemini-embedding-001 produces 3072-dimensional embeddings
// 3. Vector store dimension must match the actual embedding dimension
const dimension = getModelDimension("gemini", "text-embedding-004")
expect(dimension).toBe(3072)
})
it("should return undefined for unknown model", () => {
const dimension = getModelDimension("gemini", "unknown-model")
expect(dimension).toBeUndefined()
})
it("should return undefined for unknown provider", () => {
const dimension = getModelDimension("unknown-provider" as any, "some-model")
expect(dimension).toBeUndefined()
})
it("should return correct dimensions for openai models", () => {
expect(getModelDimension("openai", "text-embedding-3-small")).toBe(1536)
expect(getModelDimension("openai", "text-embedding-3-large")).toBe(3072)
expect(getModelDimension("openai", "text-embedding-ada-002")).toBe(1536)
})
})
describe("getModelScoreThreshold", () => {
it("should return score threshold for gemini-embedding-001", () => {
const threshold = getModelScoreThreshold("gemini", "gemini-embedding-001")
expect(threshold).toBe(0.4)
})
it("should return score threshold for deprecated text-embedding-004", () => {
const threshold = getModelScoreThreshold("gemini", "text-embedding-004")
expect(threshold).toBe(0.4)
})
it("should return undefined for unknown model", () => {
const threshold = getModelScoreThreshold("gemini", "unknown-model")
expect(threshold).toBeUndefined()
})
})
describe("getDefaultModelId", () => {
it("should return gemini-embedding-001 for gemini provider", () => {
const defaultModel = getDefaultModelId("gemini")
expect(defaultModel).toBe("gemini-embedding-001")
})
it("should return text-embedding-3-small for openai provider", () => {
const defaultModel = getDefaultModelId("openai")
expect(defaultModel).toBe("text-embedding-3-small")
})
it("should return codestral-embed-2505 for mistral provider", () => {
const defaultModel = getDefaultModelId("mistral")
expect(defaultModel).toBe("codestral-embed-2505")
})
})
})