MCPcopy Index your code
hub / github.com/simstudioai/sim / executeVectorSearchOnIds

Function executeVectorSearchOnIds

apps/sim/app/api/knowledge/search/utils.ts:364–395  ·  view source on GitHub ↗
(
  embeddingIds: string[],
  queryVector: string,
  topK: number,
  distanceThreshold: number
)

Source from the content-addressed store, hash-verified

362}
363
364async function executeVectorSearchOnIds(
365 embeddingIds: string[],
366 queryVector: string,
367 topK: number,
368 distanceThreshold: number
369): Promise<SearchResult[]> {
370 if (embeddingIds.length === 0) {
371 return []
372 }
373
374 return await db
375 .select(
376 getSearchResultFields(
377 sql<number>`${embedding.embedding} <=> ${queryVector}::vector`.as('distance')
378 )
379 )
380 .from(embedding)
381 .innerJoin(document, eq(embedding.documentId, document.id))
382 .where(
383 and(
384 inArray(embedding.id, embeddingIds),
385 eq(document.enabled, true),
386 eq(document.processingStatus, 'completed'),
387 eq(document.userExcluded, false),
388 isNull(document.archivedAt),
389 isNull(document.deletedAt),
390 sql`${embedding.embedding} <=> ${queryVector}::vector < ${distanceThreshold}`
391 )
392 )
393 .orderBy(sql`${embedding.embedding} <=> ${queryVector}::vector`)
394 .limit(topK)
395}
396
397export async function handleTagOnlySearch(params: SearchParams): Promise<SearchResult[]> {
398 const { knowledgeBaseIds, topK, structuredFilters } = params

Callers 1

handleTagAndVectorSearchFunction · 0.85

Calls 2

getSearchResultFieldsFunction · 0.85
eqFunction · 0.50

Tested by

no test coverage detected