diff --git a/apps/sim/blocks/blocks/pinecone.ts b/apps/sim/blocks/blocks/pinecone.ts index 3d01b42f702..6448569405a 100644 --- a/apps/sim/blocks/blocks/pinecone.ts +++ b/apps/sim/blocks/blocks/pinecone.ts @@ -541,6 +541,7 @@ export const PineconeBlock: BlockConfig = { vector: { type: 'json', description: 'Query vector' }, includeValues: { type: 'boolean', description: 'Include vector values' }, includeMetadata: { type: 'boolean', description: 'Include metadata' }, + options: { type: 'json', description: 'Selected vector search options' }, id: { type: 'string', description: 'Vector identifier to update' }, values: { type: 'json', description: 'New dense vector values' }, sparseValues: { type: 'json', description: 'New sparse vector values' }, diff --git a/apps/sim/tools/pinecone/search_vector.test.ts b/apps/sim/tools/pinecone/search_vector.test.ts new file mode 100644 index 00000000000..0159bed5d37 --- /dev/null +++ b/apps/sim/tools/pinecone/search_vector.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from 'vitest' +import { searchVectorTool } from '@/tools/pinecone/search_vector' + +describe('searchVectorTool', () => { + const buildBody = searchVectorTool.request.body! + const baseParams = { + indexHost: 'https://example.pinecone.io', + namespace: 'default', + vector: [0.1, 0.2], + apiKey: 'test-key', + } + + it.each([ + { + name: 'neither option', + options: [], + expected: { includeValues: false, includeMetadata: false }, + }, + { + name: 'include values only', + options: ['includeValues'], + expected: { includeValues: true, includeMetadata: false }, + }, + { + name: 'include metadata only', + options: ['includeMetadata'], + expected: { includeValues: false, includeMetadata: true }, + }, + { + name: 'both options', + options: ['includeValues', 'includeMetadata'], + expected: { includeValues: true, includeMetadata: true }, + }, + ])('maps $name to the Pinecone query flags', ({ options, expected }) => { + const body = buildBody({ ...baseParams, options }) + + expect(body).toMatchObject(expected) + }) +}) diff --git a/apps/sim/tools/pinecone/search_vector.ts b/apps/sim/tools/pinecone/search_vector.ts index c4854a40ab4..eb5e8bf02bd 100644 --- a/apps/sim/tools/pinecone/search_vector.ts +++ b/apps/sim/tools/pinecone/search_vector.ts @@ -1,6 +1,26 @@ import type { PineconeResponse, PineconeSearchVectorParams } from '@/tools/pinecone/types' import type { ToolConfig } from '@/tools/types' +function parseBoolean(value: unknown): boolean { + if (typeof value === 'boolean') return value + if (typeof value === 'number') return value !== 0 + return typeof value === 'string' && ['true', '1'].includes(value.trim().toLowerCase()) +} + +function selectedOptions(value: string[] | string | undefined): Set { + if (Array.isArray(value)) return new Set(value) + if (typeof value !== 'string' || value.trim().length === 0) return new Set() + + try { + const parsed: unknown = JSON.parse(value) + return Array.isArray(parsed) + ? new Set(parsed.filter((item): item is string => typeof item === 'string')) + : new Set() + } catch { + return new Set() + } +} + export const searchVectorTool: ToolConfig = { id: 'pinecone_search_vector', name: 'Pinecone Search Vector', @@ -51,6 +71,12 @@ export const searchVectorTool: ToolConfig | string includeValues?: boolean includeMetadata?: boolean + options?: string[] | string } export interface PineconeDeleteVectorsParams {