remcode
Version:
Turn your AI assistant into a codebase expert. Intelligent code analysis, semantic search, and software engineering guidance through MCP integration.
90 lines (89 loc) • 2.55 kB
TypeScript
import { CodeChunk, EmbeddingManagerOptions } from '../types';
interface ModelInfo {
id: string;
name: string;
embeddingDimension: number;
strategy: 'code' | 'text';
apiType: 'feature_extraction' | 'sentence_similarity';
}
export declare class EmbeddingManager {
private options;
private hfClient;
private apiBaseUrl;
private healthCheckedModels;
constructor(options: EmbeddingManagerOptions);
/**
* Initialize and validate the embedding model
* Tests the primary model and falls back to alternatives if needed
* @returns The initialized model ID and configuration
*/
initializeModel(): Promise<{
modelId: string;
modelInfo: ModelInfo;
isHealthy: boolean;
}>;
/**
* Check if a model is healthy and available via Inference API
* @param modelId The model ID to check
* @returns True if the model is available and working
*/
checkModelHealth(modelId: string): Promise<boolean>;
/**
* Get available models with their health status
* @returns Array of available models with health information
*/
getAvailableModelsWithHealth(): Promise<Array<ModelInfo & {
isHealthy: boolean;
}>>;
/**
* Embeds code chunks using the specified model
* @param chunks Array of code chunks to embed
* @returns The chunks with embeddings added
*/
embedChunks(chunks: CodeChunk[]): Promise<CodeChunk[]>;
/**
* Embeds a single code chunk
*/
private embedSingleChunk;
/**
* Embeds a single chunk with fallback strategy
*/
private embedSingleChunkWithFallback;
/**
* Gets an embedding from the HuggingFace model
*/
private getEmbeddingFromModel;
/**
* Get embedding via direct API call
*/
private getEmbeddingViaDirectAPI;
/**
* Process embedding result from API based on model type
*/
private processEmbeddingResult;
/**
* Preprocess text for better embedding quality
*/
private preprocessText;
/**
* Get dimension for a specific model
*/
private getDimensionForModel;
/**
* Averages token embeddings to get a single vector
*/
private averageEmbeddings;
/**
* Generates random embeddings as a fallback
*/
private generateRandomEmbeddings;
/**
* Get model information
*/
getModelInfo(modelId?: string): ModelInfo;
/**
* List available models
*/
getAvailableModels(): ModelInfo[];
}
export {};