import type { PodChatKitStore } from '../chatkit/pod-store'; import type { AuthContext } from '../auth/AuthContext'; import type { EmbeddingService } from '../../ai/service/EmbeddingService'; /** * Vector upsert request */ export interface VectorUpsertRequest { /** Embedding model name */ model: string; /** Vectors to upsert */ vectors: Array<{ /** Resource URI */ subject: string; /** Semantic aspect (type, chunk, property) */ aspect: string; /** Vector data */ vector: number[]; }>; } /** * Vector search request */ export interface VectorSearchRequest { /** Embedding model name */ model: string; /** Query text (will be converted to vector) */ query?: string; /** Pre-computed query vector */ vector?: number[]; /** Max results */ limit?: number; /** Similarity threshold (0-1) */ threshold?: number; /** Filter conditions */ filter?: { subject?: { $eq?: string; $startsWith?: string; $in?: string[]; }; aspect?: { $eq?: string; $startsWith?: string; $in?: string[]; }; }; /** Deduplicate by subject */ distinctSubject?: boolean; } /** * Vector search result */ export interface VectorSearchResult { subject: string; aspect: string; score: number; distance: number; } /** * Vector delete request */ export interface VectorDeleteRequest { /** Embedding model name */ model: string; /** Filter conditions (at least one field required) */ filter: { subject?: { $eq?: string; $startsWith?: string; }; aspect?: { $eq?: string; $startsWith?: string; }; }; } /** * Vector status response */ export interface VectorStatusResponse { byModel: Array<{ model: string; count: number; }>; totalCount: number; } export interface VectorServiceOptions { /** CSS base URL for vector API */ cssBaseUrl: string; /** Pod store for getting AI credentials */ store: PodChatKitStore; /** Embedding service for generating vectors */ embeddingService: EmbeddingService; } /** * VectorService - API Server 的向量服务 * * 负责: * 1. 从 Pod 读取 AI 凭据 * 2. 调用 EmbeddingService 生成向量 * 3. 调用 CSS 的 /-/vector/* 端点存储/搜索向量 */ export declare class VectorService { private readonly logger; private readonly cssBaseUrl; private readonly store; private readonly embeddingService; constructor(options: VectorServiceOptions); /** * Upsert vectors to CSS vector store */ upsert(request: VectorUpsertRequest, auth: AuthContext, accessToken: string): Promise<{ upserted: number; errors: string[]; took_ms: number; }>; /** * Search vectors in CSS vector store */ search(request: VectorSearchRequest, auth: AuthContext, accessToken: string): Promise<{ results: VectorSearchResult[]; model: string; took_ms: number; }>; /** * Delete vectors from CSS vector store */ delete(request: VectorDeleteRequest, auth: AuthContext, accessToken: string): Promise<{ deleted: number; errors: string[]; took_ms: number; }>; /** * Get vector store status */ status(accessToken: string): Promise; /** * Generate embedding for text */ embed(text: string, model: string, auth: AuthContext): Promise; /** * Generate embeddings for multiple texts */ embedBatch(texts: string[], model: string, auth: AuthContext): Promise; /** * Create a StoreContext from AuthContext for Pod operations */ private createStoreContext; private getAiCredential; private callCssVectorApi; /** * Hash subject + aspect to numeric ID * Uses FNV-1a hash for good distribution */ private hashSubjectAspect; }