import { DyFM_DataModel_Params, DyFM_DBFilter, DyFM_Metadata } from '@futdevpro/fsm-dynamo'; import { DyFM_OAI_Settings } from '@futdevpro/fsm-dynamo/ai/open-ai'; import { LVS_Search_Mode } from '../_enums/lvs-search-mode.enum'; import { DyNTS_OAI_VectorDataService } from '../../ai/_modules/open-ai/_services/data-services/oai-vector-data.service'; /** * Local Vector Data Service * Extends {@link DyNTS_OAI_VectorDataService} to perform in-memory vector similarity search * instead of MongoDB vector search * * This service loads data from the database, builds an in-memory vector pool, * and performs brute-force vector similarity search using cosine similarity or L2 distance * * @example * ```typescript * const service = new DyNTS_OAI_LocalVectorDataService( * data, * dataParams, * openAISettings, * issuer * ); * * const results = await service.vectorSearch({ * input: 'search query', * searchInKey: 'contentVectorized', * limit: 10, * filterBy: { category: 'docs' } * }); * ``` */ export declare class DyNTS_LVS_VectorDataService extends DyNTS_OAI_VectorDataService { /** * Default search mode * Cosine similarity is typically preferred for text embeddings */ defaultSearchMode: LVS_Search_Mode; /** * Whether to use L2 normalization when storing vectors * Normalized vectors are more efficient for cosine similarity calculations */ useL2Normalization: boolean; /** * Instance-based vector pool utility * Minden service instance saját vektor pool-t tart fenn */ private vectorPool; constructor( /** * Initial data, this will be used by functions on default */ data: T, /** * DB data params will be used to connect to usable dbService on GlobalService */ dataParams: DyFM_DataModel_Params, /** * OpenAI settings */ openAISettings: DyFM_OAI_Settings, /** * Initial set for issuer to be able to follow the issuer's activity */ issuer: string); /** * Overrides the parent vectorSearch method to perform local in-memory vector search * * Process: * 1. Load data from DB using filterBy (if provided) or getAll() * 2. Extract vectorized properties from loaded data * 3. Build in-memory vector pool * 4. Vectorize input query * 5. Perform local vector search * 6. Map search results back to full data objects * * @param set Search parameters * @returns Array of data objects sorted by similarity score */ vectorSearch(set: { input: string; /** this should be the vectorized property key */ searchInKey: string; limit?: number; /** * Number of candidates that are used to find the best match * (Not used in local search, but kept for compatibility) */ numberOfCandidates?: number; /** * Filter to narrow down candidates from DB before vector search */ filterBy?: DyFM_DBFilter; /** * Search mode (cosine similarity, L2 distance, or hybrid). * Defaults to this.defaultSearchMode. * * `hybrid` mode combines cosine similarity (vector half) with BM25 * text scoring (text half) — `textSearchKey` is REQUIRED in hybrid mode. */ searchMode?: LVS_Search_Mode; /** * Csak `hybrid` modban — weighted score-merge a cosine es a BM25 kozott. * Default: { vector: 0.5, text: 0.5 }. Mindkettonek 0..1 tartomany javasolt. */ hybridWeight?: { vector: number; text: number; }; /** * Csak `hybrid` modban — KOTELEZO; melyik string property-n fut a BM25 * text-search. NEM kell hogy a vectorized property legyen. */ textSearchKey?: keyof T; }): Promise; } /** * @example * ```typescript * // Create a local vector data service * const localVectorService = new DyNTS_OAI_LocalVectorDataService( * new CodeChunk(), * codeChunk_dataParams, * openAISettings, * 'example-issuer' * ); * * // Perform vector search with filterBy * const results = await localVectorService.vectorSearch({ * input: 'How to implement authentication?', * searchInKey: 'chunkParentedContentVectorized', * limit: 5, * filterBy: { * // Filter by category before vector search * category: 'documentation' * }, * searchMode: LVS_Search_Mode.cosineSimilarity * }); * * // Results are sorted by similarity score (highest first for cosine) * console.log(`Found ${results.length} similar chunks`); * * // Access the results * for (const result of results) { * console.log(`Chunk ID: ${result._id}, Content: ${result.chunkContent}`); * } * ``` */ //# sourceMappingURL=lvs-local-vector-search.data-service.d.ts.map