fixed hardcoded embeddingDims (#3537)
This commit is contained in:
@@ -5,6 +5,7 @@ import { EmbeddingConfig } from "../types";
|
||||
export class AzureOpenAIEmbedder implements Embedder {
|
||||
private client: AzureOpenAI;
|
||||
private model: string;
|
||||
private embeddingDims?: number;
|
||||
|
||||
constructor(config: EmbeddingConfig) {
|
||||
if (!config.apiKey || !config.modelProperties?.endpoint) {
|
||||
@@ -19,6 +20,7 @@ export class AzureOpenAIEmbedder implements Embedder {
|
||||
...rest,
|
||||
});
|
||||
this.model = config.model || "text-embedding-3-small";
|
||||
this.embeddingDims = config.embeddingDims || 1536;
|
||||
}
|
||||
|
||||
async embed(text: string): Promise<number[]> {
|
||||
|
||||
@@ -5,17 +5,21 @@ import { EmbeddingConfig } from "../types";
|
||||
export class GoogleEmbedder implements Embedder {
|
||||
private google: GoogleGenAI;
|
||||
private model: string;
|
||||
private embeddingDims?: number;
|
||||
|
||||
constructor(config: EmbeddingConfig) {
|
||||
this.google = new GoogleGenAI({ apiKey: config.apiKey });
|
||||
this.model = config.model || "text-embedding-004";
|
||||
this.google = new GoogleGenAI({
|
||||
apiKey: config.apiKey || process.env.GOOGLE_API_KEY,
|
||||
});
|
||||
this.model = config.model || "gemini-embedding-001";
|
||||
this.embeddingDims = config.embeddingDims || 1536;
|
||||
}
|
||||
|
||||
async embed(text: string): Promise<number[]> {
|
||||
const response = await this.google.models.embedContent({
|
||||
model: this.model,
|
||||
contents: text,
|
||||
config: { outputDimensionality: 768 },
|
||||
config: { outputDimensionality: this.embeddingDims },
|
||||
});
|
||||
return response.embeddings![0].values!;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { logger } from "../utils/logger";
|
||||
export class OllamaEmbedder implements Embedder {
|
||||
private ollama: Ollama;
|
||||
private model: string;
|
||||
private embeddingDims?: number;
|
||||
// Using this variable to avoid calling the Ollama server multiple times
|
||||
private initialized: boolean = false;
|
||||
|
||||
@@ -14,6 +15,7 @@ export class OllamaEmbedder implements Embedder {
|
||||
host: config.url || "http://localhost:11434",
|
||||
});
|
||||
this.model = config.model || "nomic-embed-text:latest";
|
||||
this.embeddingDims = config.embeddingDims || 768;
|
||||
this.ensureModelExists().catch((err) => {
|
||||
logger.error(`Error ensuring model exists: ${err}`);
|
||||
});
|
||||
|
||||
@@ -5,10 +5,12 @@ import { EmbeddingConfig } from "../types";
|
||||
export class OpenAIEmbedder implements Embedder {
|
||||
private openai: OpenAI;
|
||||
private model: string;
|
||||
private embeddingDims?: number;
|
||||
|
||||
constructor(config: EmbeddingConfig) {
|
||||
this.openai = new OpenAI({ apiKey: config.apiKey });
|
||||
this.model = config.model || "text-embedding-3-small";
|
||||
this.embeddingDims = config.embeddingDims || 1536;
|
||||
}
|
||||
|
||||
async embed(text: string): Promise<number[]> {
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface EmbeddingConfig {
|
||||
apiKey?: string;
|
||||
model?: string | any;
|
||||
url?: string;
|
||||
embeddingDims?: number;
|
||||
modelProperties?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user