(params: SearchParams)
| 513 | } |
| 514 | |
| 515 | export async function handleTagAndVectorSearch(params: SearchParams): Promise<SearchResult[]> { |
| 516 | const { knowledgeBaseIds, topK, structuredFilters, queryVector, distanceThreshold } = params |
| 517 | |
| 518 | if (!structuredFilters || structuredFilters.length === 0) { |
| 519 | throw new Error('Tag filters are required for tag and vector search') |
| 520 | } |
| 521 | if (!queryVector || !distanceThreshold) { |
| 522 | throw new Error('Query vector and distance threshold are required for tag and vector search') |
| 523 | } |
| 524 | |
| 525 | // Step 1: Filter by tags first |
| 526 | const tagFilteredIds = await executeTagFilterQuery(knowledgeBaseIds, structuredFilters) |
| 527 | |
| 528 | if (tagFilteredIds.length === 0) { |
| 529 | return [] |
| 530 | } |
| 531 | |
| 532 | // Step 2: Perform vector search only on tag-filtered results |
| 533 | return await executeVectorSearchOnIds( |
| 534 | tagFilteredIds.map((r) => r.id), |
| 535 | queryVector, |
| 536 | topK, |
| 537 | distanceThreshold |
| 538 | ) |
| 539 | } |
no test coverage detected