mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
fix voyage.ts typescript issues
This commit is contained in:
parent
614d5ccdd3
commit
c046343349
@ -69,8 +69,7 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
dimension,
|
dimension,
|
||||||
contextWindow,
|
contextWidth: contextWindow,
|
||||||
guaranteesNormalization: true, // Voyage embeddings are typically normalized
|
|
||||||
name: modelName,
|
name: modelName,
|
||||||
type: 'float32'
|
type: 'float32'
|
||||||
};
|
};
|
||||||
@ -86,12 +85,12 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
async getModelInfo(modelName: string): Promise<EmbeddingModelInfo> {
|
async getModelInfo(modelName: string): Promise<EmbeddingModelInfo> {
|
||||||
// Check cache first
|
// Check cache first
|
||||||
if (this.modelInfoCache.has(modelName)) {
|
if (this.modelInfoCache.has(modelName)) {
|
||||||
return this.modelInfoCache.get(modelName);
|
return this.modelInfoCache.get(modelName)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to determine model capabilities
|
// Try to determine model capabilities
|
||||||
const capabilities = await this.fetchModelCapabilities(modelName);
|
const capabilities = await this.fetchModelCapabilities(modelName);
|
||||||
const contextWindow = capabilities?.contextWindow || 8192; // Default context window for Voyage
|
const contextWindow = capabilities?.contextWidth || 8192; // Default context window for Voyage
|
||||||
const knownDimension = capabilities?.dimension || 1024; // Default dimension for Voyage models
|
const knownDimension = capabilities?.dimension || 1024; // Default dimension for Voyage models
|
||||||
|
|
||||||
// For Voyage, we can use known dimensions or detect with a test call
|
// For Voyage, we can use known dimensions or detect with a test call
|
||||||
@ -100,8 +99,7 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
// Use known dimension
|
// Use known dimension
|
||||||
const modelInfo: EmbeddingModelInfo = {
|
const modelInfo: EmbeddingModelInfo = {
|
||||||
dimension: knownDimension,
|
dimension: knownDimension,
|
||||||
contextWindow,
|
contextWidth: contextWindow,
|
||||||
guaranteesNormalization: true, // Voyage embeddings are typically normalized
|
|
||||||
name: modelName,
|
name: modelName,
|
||||||
type: 'float32'
|
type: 'float32'
|
||||||
};
|
};
|
||||||
@ -120,16 +118,14 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
if (modelName.includes('voyage-2')) {
|
if (modelName.includes('voyage-2')) {
|
||||||
return {
|
return {
|
||||||
dimension: dimension || 1024,
|
dimension: dimension || 1024,
|
||||||
contextWindow: 4096,
|
contextWidth: 4096,
|
||||||
guaranteesNormalization: true, // Voyage-2 embeddings are normalized
|
|
||||||
name: modelName,
|
name: modelName,
|
||||||
type: 'float32'
|
type: 'float32'
|
||||||
};
|
};
|
||||||
} else if (modelName.includes('voyage-lite-02')) {
|
} else if (modelName.includes('voyage-lite-02')) {
|
||||||
return {
|
return {
|
||||||
dimension: dimension || 768,
|
dimension: dimension || 768,
|
||||||
contextWindow: 4096,
|
contextWidth: 4096,
|
||||||
guaranteesNormalization: true, // Voyage-lite embeddings are normalized
|
|
||||||
name: modelName,
|
name: modelName,
|
||||||
type: 'float32'
|
type: 'float32'
|
||||||
};
|
};
|
||||||
@ -137,8 +133,7 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
// Default for other Voyage models
|
// Default for other Voyage models
|
||||||
return {
|
return {
|
||||||
dimension: dimension || 1024,
|
dimension: dimension || 1024,
|
||||||
contextWindow: 4096,
|
contextWidth: 4096,
|
||||||
guaranteesNormalization: true, // Assuming all Voyage embeddings are normalized
|
|
||||||
name: modelName,
|
name: modelName,
|
||||||
type: 'float32'
|
type: 'float32'
|
||||||
};
|
};
|
||||||
@ -150,8 +145,7 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
// Use default parameters if everything else fails
|
// Use default parameters if everything else fails
|
||||||
const defaultModelInfo: EmbeddingModelInfo = {
|
const defaultModelInfo: EmbeddingModelInfo = {
|
||||||
dimension: 1024, // Default for Voyage models
|
dimension: 1024, // Default for Voyage models
|
||||||
contextWindow: 8192,
|
contextWidth: 8192,
|
||||||
guaranteesNormalization: true, // Voyage embeddings are typically normalized
|
|
||||||
name: modelName,
|
name: modelName,
|
||||||
type: 'float32'
|
type: 'float32'
|
||||||
};
|
};
|
||||||
@ -176,7 +170,7 @@ export class VoyageEmbeddingProvider extends BaseEmbeddingProvider {
|
|||||||
const modelInfo = await this.getModelInfo(modelName);
|
const modelInfo = await this.getModelInfo(modelName);
|
||||||
|
|
||||||
// Trim text if it might exceed context window (rough character estimate)
|
// Trim text if it might exceed context window (rough character estimate)
|
||||||
const charLimit = modelInfo.contextWindow * 4; // Rough estimate: avg 4 chars per token
|
const charLimit = (modelInfo.contextWidth || 4096) * 4; // Rough estimate: avg 4 chars per token
|
||||||
const trimmedText = text.length > charLimit ? text.substring(0, charLimit) : text;
|
const trimmedText = text.length > charLimit ? text.substring(0, charLimit) : text;
|
||||||
|
|
||||||
const response = await fetch(`${this.baseUrl}/embeddings`, {
|
const response = await fetch(`${this.baseUrl}/embeddings`, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user