fixed hardcoded embeddingDims (#3537)
This commit is contained in:
@@ -117,9 +117,20 @@ Refer to [Azure Identity troubleshooting tips](https://github.com/Azure/azure-sd
|
|||||||
### Config
|
### Config
|
||||||
|
|
||||||
Here are the parameters available for configuring Azure OpenAI embedder:
|
Here are the parameters available for configuring Azure OpenAI embedder:
|
||||||
|
<Tabs>
|
||||||
|
<Tab title="Python">
|
||||||
| Parameter | Description | Default Value |
|
| Parameter | Description | Default Value |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `model` | The name of the embedding model to use | `text-embedding-3-small` |
|
| `model` | The name of the embedding model to use | `text-embedding-3-small` |
|
||||||
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
||||||
| `azure_kwargs` | The Azure OpenAI configs | `config_keys` |
|
| `azure_kwargs` | The Azure OpenAI configs | `config_keys` |
|
||||||
|
</Tab>
|
||||||
|
<Tab title="TypeScript">
|
||||||
|
| Parameter | Description | Default Value |
|
||||||
|
| ----------------- | --------------------------------------------- | -------------------------- |
|
||||||
|
| `model` | The name of the embedding model to use | `text-embedding-3-small` |
|
||||||
|
| `embeddingDims` | Dimensions of the embedding model | `1536` |
|
||||||
|
| `apiKey` | Azure OpenAI API key | `None` |
|
||||||
|
| `modelProperties` | Object containing endpoint and other settings | `{ endpoint: "",...rest }`|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ import { Memory } from 'mem0ai/oss';
|
|||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
embedder: {
|
embedder: {
|
||||||
provider: 'google',
|
provider: "google",
|
||||||
config: {
|
config: {
|
||||||
apiKey: process.env.GOOGLE_API_KEY || '',
|
apiKey: process.env["GOOGLE_API_KEY"],
|
||||||
model: 'text-embedding-004',
|
model: "gemini-embedding-001",
|
||||||
// The output dimensionality is fixed at 768 for Google AI embeddings
|
embeddingDims: 1536,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const memory = new Memory(config);
|
const memory = new Memory(config);
|
||||||
@@ -61,9 +61,19 @@ await memory.add(messages, { userId: "john" });
|
|||||||
### Config
|
### Config
|
||||||
|
|
||||||
Here are the parameters available for configuring Gemini embedder:
|
Here are the parameters available for configuring Gemini embedder:
|
||||||
|
<Tabs>
|
||||||
| Parameter | Description | Default Value |
|
<Tab title="Python">
|
||||||
| --- | --- | --- |
|
| Parameter | Description | Default Value |
|
||||||
| `model` | The name of the embedding model to use | `models/text-embedding-004` |
|
| ---------------- | ------------------------------------ | ----------------------- |
|
||||||
| `embedding_dims` | Dimensions of the embedding model (output_dimensionality will be considered as embedding_dims, so please set embedding_dims accordingly) | `768` |
|
| `model` | The name of the embedding model to use| `models/text-embedding-004` |
|
||||||
| `api_key` | The Google API key | `None` |
|
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
||||||
|
| `api_key` | The Google API key | `None` |
|
||||||
|
</Tab>
|
||||||
|
<Tab title="TypeScript">
|
||||||
|
| Parameter | Description | Default Value |
|
||||||
|
| ----------------- | --------------------------------------------- | -------------------------- |
|
||||||
|
| `model` | The name of the embedding model to use | `gemini-embedding-001` |
|
||||||
|
| `embeddingDims` | Dimensions of the embedding model | `1536` |
|
||||||
|
| `apiKey` | Google API key | `None` |
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|||||||
@@ -69,5 +69,6 @@ Here are the parameters available for configuring Ollama embedder:
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `model` | The name of the Ollama model to use | `nomic-embed-text:latest` |
|
| `model` | The name of the Ollama model to use | `nomic-embed-text:latest` |
|
||||||
| `url` | Base URL for Ollama server | `http://localhost:11434` |
|
| `url` | Base URL for Ollama server | `http://localhost:11434` |
|
||||||
|
| `embeddingDims` | Dimensions of the embedding model | 768
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
@@ -23,7 +23,7 @@ config = {
|
|||||||
"embedder": {
|
"embedder": {
|
||||||
"provider": "azure_openai",
|
"provider": "azure_openai",
|
||||||
"config": {
|
"config": {
|
||||||
"model": "text-embedding-3-large"
|
"model": "text-embedding-3-large",
|
||||||
"azure_kwargs": {
|
"azure_kwargs": {
|
||||||
"api_version": "",
|
"api_version": "",
|
||||||
"azure_deployment": "",
|
"azure_deployment": "",
|
||||||
@@ -117,9 +117,20 @@ Refer to [Azure Identity troubleshooting tips](https://github.com/Azure/azure-sd
|
|||||||
### Config
|
### Config
|
||||||
|
|
||||||
Here are the parameters available for configuring Azure OpenAI embedder:
|
Here are the parameters available for configuring Azure OpenAI embedder:
|
||||||
|
<Tabs>
|
||||||
|
<Tab title="Python">
|
||||||
| Parameter | Description | Default Value |
|
| Parameter | Description | Default Value |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `model` | The name of the embedding model to use | `text-embedding-3-small` |
|
| `model` | The name of the embedding model to use | `text-embedding-3-small` |
|
||||||
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
||||||
| `azure_kwargs` | The Azure OpenAI configs | `config_keys` |
|
| `azure_kwargs` | The Azure OpenAI configs | `config_keys` |
|
||||||
|
</Tab>
|
||||||
|
<Tab title="TypeScript">
|
||||||
|
| Parameter | Description | Default Value |
|
||||||
|
| ----------------- | --------------------------------------------- | -------------------------- |
|
||||||
|
| `model` | The name of the embedding model to use | `text-embedding-3-small` |
|
||||||
|
| `embeddingDims` | Dimensions of the embedding model | `1536` |
|
||||||
|
| `apiKey` | Azure OpenAI API key | `None` |
|
||||||
|
| `modelProperties` | Object containing endpoint and other settings | `{ endpoint: "",...rest }`|
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ import { Memory } from 'mem0ai/oss';
|
|||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
embedder: {
|
embedder: {
|
||||||
provider: 'google',
|
provider: "google",
|
||||||
config: {
|
config: {
|
||||||
apiKey: process.env.GOOGLE_API_KEY || '',
|
apiKey: process.env["GOOGLE_API_KEY"],
|
||||||
model: 'text-embedding-004',
|
model: "gemini-embedding-001",
|
||||||
// The output dimensionality is fixed at 768 for Google AI embeddings
|
embeddingDims: 1536,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const memory = new Memory(config);
|
const memory = new Memory(config);
|
||||||
@@ -62,8 +62,19 @@ await memory.add(messages, { userId: "john" });
|
|||||||
|
|
||||||
Here are the parameters available for configuring Gemini embedder:
|
Here are the parameters available for configuring Gemini embedder:
|
||||||
|
|
||||||
| Parameter | Description | Default Value |
|
<Tabs>
|
||||||
| --- | --- | --- |
|
<Tab title="Python">
|
||||||
| `model` | The name of the embedding model to use | `models/text-embedding-004` |
|
| Parameter | Description | Default Value |
|
||||||
| `embedding_dims` | Dimensions of the embedding model (output_dimensionality will be considered as embedding_dims, so please set embedding_dims accordingly) | `768` |
|
| ---------------- | ------------------------------------ | ----------------------- |
|
||||||
| `api_key` | The Google API key | `None` |
|
| `model` | The name of the embedding model to use| `models/text-embedding-004` |
|
||||||
|
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
||||||
|
| `api_key` | The Google API key | `None` |
|
||||||
|
</Tab>
|
||||||
|
<Tab title="TypeScript">
|
||||||
|
| Parameter | Description | Default Value |
|
||||||
|
| ----------------- | --------------------------------------------- | -------------------------- |
|
||||||
|
| `model` | The name of the embedding model to use | `gemini-embedding-001` |
|
||||||
|
| `embeddingDims` | Dimensions of the embedding model | `1536` |
|
||||||
|
| `apiKey` | Google API key | `None` |
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|||||||
@@ -69,5 +69,6 @@ Here are the parameters available for configuring Ollama embedder:
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `model` | The name of the Ollama model to use | `nomic-embed-text:latest` |
|
| `model` | The name of the Ollama model to use | `nomic-embed-text:latest` |
|
||||||
| `url` | Base URL for Ollama server | `http://localhost:11434` |
|
| `url` | Base URL for Ollama server | `http://localhost:11434` |
|
||||||
|
| `embeddingDims` | Dimensions of the embedding model | 768 |
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
@@ -5,6 +5,7 @@ import { EmbeddingConfig } from "../types";
|
|||||||
export class AzureOpenAIEmbedder implements Embedder {
|
export class AzureOpenAIEmbedder implements Embedder {
|
||||||
private client: AzureOpenAI;
|
private client: AzureOpenAI;
|
||||||
private model: string;
|
private model: string;
|
||||||
|
private embeddingDims?: number;
|
||||||
|
|
||||||
constructor(config: EmbeddingConfig) {
|
constructor(config: EmbeddingConfig) {
|
||||||
if (!config.apiKey || !config.modelProperties?.endpoint) {
|
if (!config.apiKey || !config.modelProperties?.endpoint) {
|
||||||
@@ -19,6 +20,7 @@ export class AzureOpenAIEmbedder implements Embedder {
|
|||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
this.model = config.model || "text-embedding-3-small";
|
this.model = config.model || "text-embedding-3-small";
|
||||||
|
this.embeddingDims = config.embeddingDims || 1536;
|
||||||
}
|
}
|
||||||
|
|
||||||
async embed(text: string): Promise<number[]> {
|
async embed(text: string): Promise<number[]> {
|
||||||
|
|||||||
@@ -5,17 +5,21 @@ import { EmbeddingConfig } from "../types";
|
|||||||
export class GoogleEmbedder implements Embedder {
|
export class GoogleEmbedder implements Embedder {
|
||||||
private google: GoogleGenAI;
|
private google: GoogleGenAI;
|
||||||
private model: string;
|
private model: string;
|
||||||
|
private embeddingDims?: number;
|
||||||
|
|
||||||
constructor(config: EmbeddingConfig) {
|
constructor(config: EmbeddingConfig) {
|
||||||
this.google = new GoogleGenAI({ apiKey: config.apiKey });
|
this.google = new GoogleGenAI({
|
||||||
this.model = config.model || "text-embedding-004";
|
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[]> {
|
async embed(text: string): Promise<number[]> {
|
||||||
const response = await this.google.models.embedContent({
|
const response = await this.google.models.embedContent({
|
||||||
model: this.model,
|
model: this.model,
|
||||||
contents: text,
|
contents: text,
|
||||||
config: { outputDimensionality: 768 },
|
config: { outputDimensionality: this.embeddingDims },
|
||||||
});
|
});
|
||||||
return response.embeddings![0].values!;
|
return response.embeddings![0].values!;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { logger } from "../utils/logger";
|
|||||||
export class OllamaEmbedder implements Embedder {
|
export class OllamaEmbedder implements Embedder {
|
||||||
private ollama: Ollama;
|
private ollama: Ollama;
|
||||||
private model: string;
|
private model: string;
|
||||||
|
private embeddingDims?: number;
|
||||||
// Using this variable to avoid calling the Ollama server multiple times
|
// Using this variable to avoid calling the Ollama server multiple times
|
||||||
private initialized: boolean = false;
|
private initialized: boolean = false;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ export class OllamaEmbedder implements Embedder {
|
|||||||
host: config.url || "http://localhost:11434",
|
host: config.url || "http://localhost:11434",
|
||||||
});
|
});
|
||||||
this.model = config.model || "nomic-embed-text:latest";
|
this.model = config.model || "nomic-embed-text:latest";
|
||||||
|
this.embeddingDims = config.embeddingDims || 768;
|
||||||
this.ensureModelExists().catch((err) => {
|
this.ensureModelExists().catch((err) => {
|
||||||
logger.error(`Error ensuring model exists: ${err}`);
|
logger.error(`Error ensuring model exists: ${err}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ import { EmbeddingConfig } from "../types";
|
|||||||
export class OpenAIEmbedder implements Embedder {
|
export class OpenAIEmbedder implements Embedder {
|
||||||
private openai: OpenAI;
|
private openai: OpenAI;
|
||||||
private model: string;
|
private model: string;
|
||||||
|
private embeddingDims?: number;
|
||||||
|
|
||||||
constructor(config: EmbeddingConfig) {
|
constructor(config: EmbeddingConfig) {
|
||||||
this.openai = new OpenAI({ apiKey: config.apiKey });
|
this.openai = new OpenAI({ apiKey: config.apiKey });
|
||||||
this.model = config.model || "text-embedding-3-small";
|
this.model = config.model || "text-embedding-3-small";
|
||||||
|
this.embeddingDims = config.embeddingDims || 1536;
|
||||||
}
|
}
|
||||||
|
|
||||||
async embed(text: string): Promise<number[]> {
|
async embed(text: string): Promise<number[]> {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export interface EmbeddingConfig {
|
|||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
model?: string | any;
|
model?: string | any;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
embeddingDims?: number;
|
||||||
modelProperties?: Record<string, any>;
|
modelProperties?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user