Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/sim/blocks/blocks/pinecone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
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' },
Expand Down
39 changes: 39 additions & 0 deletions apps/sim/tools/pinecone/search_vector.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
34 changes: 32 additions & 2 deletions apps/sim/tools/pinecone/search_vector.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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<PineconeSearchVectorParams, PineconeResponse> = {
id: 'pinecone_search_vector',
name: 'Pinecone Search Vector',
Expand Down Expand Up @@ -51,6 +71,12 @@ export const searchVectorTool: ToolConfig<PineconeSearchVectorParams, PineconeRe
visibility: 'user-or-llm',
description: 'Include metadata in response (true/false)',
},
options: {
type: 'array',
required: false,
visibility: 'user-only',
description: 'Selected search result options',
},
apiKey: {
type: 'string',
required: true,
Expand All @@ -76,8 +102,12 @@ export const searchVectorTool: ToolConfig<PineconeSearchVectorParams, PineconeRe
? JSON.parse(params.filter)
: params.filter
: undefined,
includeValues: true, //TODO: Make this dynamic
includeMetadata: true, //TODO: Make this dynamic
includeValues: params.options
? selectedOptions(params.options).has('includeValues')
: parseBoolean(params.includeValues),
includeMetadata: params.options
? selectedOptions(params.options).has('includeMetadata')
: parseBoolean(params.includeMetadata),
Comment thread
BillLeoutsakosvl346 marked this conversation as resolved.
}),
},

Expand Down
1 change: 1 addition & 0 deletions apps/sim/tools/pinecone/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export interface PineconeSearchVectorParams extends PineconeBaseParams {
filter?: Record<string, any> | string
includeValues?: boolean
includeMetadata?: boolean
options?: string[] | string
}

export interface PineconeDeleteVectorsParams {
Expand Down
Loading