MCPcopy Create free account
hub / github.com/MemTensor/MemOS / vectorSearch

Function vectorSearch

packages/memos-core/src/storage/vector.ts:26–42  ·  view source on GitHub ↗
(
  store: SqliteStore,
  queryVec: number[],
  topK: number,
  maxChunks?: number,
  ownerFilter?: string[],
)

Source from the content-addressed store, hash-verified

24 * When maxChunks > 0, only searches the most recent maxChunks chunks (uses index; avoids full scan as data grows).
25 */
26export function vectorSearch(
27 store: SqliteStore,
28 queryVec: number[],
29 topK: number,
30 maxChunks?: number,
31 ownerFilter?: string[],
32): VectorHit[] {
33 const all = maxChunks != null && maxChunks > 0
34 ? store.getRecentEmbeddings(maxChunks, ownerFilter)
35 : store.getAllEmbeddings(ownerFilter);
36 const scored: VectorHit[] = all.map((row) => ({
37 chunkId: row.chunkId,
38 score: cosineSimilarity(queryVec, row.vector),
39 }));
40 scored.sort((a, b) => b.score - a.score);
41 return scored.slice(0, topK);
42}

Callers 2

searchMethod · 0.90
serveSearchMethod · 0.90

Calls 4

mapMethod · 0.80
cosineSimilarityFunction · 0.70
getRecentEmbeddingsMethod · 0.45
getAllEmbeddingsMethod · 0.45

Tested by

no test coverage detected