mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
feat(pinecone): added pinecone search by vector tool & fixed dropdown tag for evaluator
This commit is contained in:
@@ -20,7 +20,8 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
|
||||
options: [
|
||||
{ label: 'Generate Embeddings', id: 'generate' },
|
||||
{ label: 'Upsert Text', id: 'upsert_text' },
|
||||
{ label: 'Search Text', id: 'search_text' },
|
||||
{ label: 'Search With Text', id: 'search_text' },
|
||||
{ label: 'Search With Vector', id: 'search_vector' },
|
||||
{ label: 'Fetch Vectors', id: 'fetch' },
|
||||
],
|
||||
},
|
||||
@@ -153,6 +154,50 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
|
||||
placeholder: '["vec1", "vec2"]',
|
||||
condition: { field: 'operation', value: 'fetch' },
|
||||
},
|
||||
// Add vector search fields
|
||||
{
|
||||
id: 'indexHost',
|
||||
title: 'Index Host',
|
||||
type: 'short-input',
|
||||
layout: 'full',
|
||||
placeholder: 'https://index-name-abc123.svc.project-id.pinecone.io',
|
||||
condition: { field: 'operation', value: 'search_vector' },
|
||||
},
|
||||
{
|
||||
id: 'namespace',
|
||||
title: 'Namespace',
|
||||
type: 'short-input',
|
||||
layout: 'full',
|
||||
placeholder: 'default',
|
||||
condition: { field: 'operation', value: 'search_vector' },
|
||||
},
|
||||
{
|
||||
id: 'vector',
|
||||
title: 'Query Vector',
|
||||
type: 'long-input',
|
||||
layout: 'full',
|
||||
placeholder: '[0.1, 0.2, 0.3, ...]',
|
||||
condition: { field: 'operation', value: 'search_vector' },
|
||||
},
|
||||
{
|
||||
id: 'topK',
|
||||
title: 'Top K Results',
|
||||
type: 'short-input',
|
||||
layout: 'full',
|
||||
placeholder: '10',
|
||||
condition: { field: 'operation', value: 'search_vector' },
|
||||
},
|
||||
{
|
||||
id: 'options',
|
||||
title: 'Options',
|
||||
type: 'checkbox-list',
|
||||
layout: 'full',
|
||||
options: [
|
||||
{ id: 'includeValues', label: 'Include Values' },
|
||||
{ id: 'includeMetadata', label: 'Include Metadata' },
|
||||
],
|
||||
condition: { field: 'operation', value: 'search_vector' },
|
||||
},
|
||||
// Common fields
|
||||
{
|
||||
id: 'apiKey',
|
||||
@@ -169,6 +214,7 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
|
||||
'pinecone_generate_embeddings',
|
||||
'pinecone_upsert_text',
|
||||
'pinecone_search_text',
|
||||
'pinecone_search_vector',
|
||||
'pinecone_fetch',
|
||||
],
|
||||
config: {
|
||||
@@ -182,6 +228,8 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
|
||||
return 'pinecone_search_text'
|
||||
case 'fetch':
|
||||
return 'pinecone_fetch'
|
||||
case 'search_vector':
|
||||
return 'pinecone_search_vector'
|
||||
default:
|
||||
throw new Error('Invalid operation selected')
|
||||
}
|
||||
@@ -192,8 +240,6 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
|
||||
inputs: {
|
||||
operation: { type: 'string', required: true },
|
||||
apiKey: { type: 'string', required: true },
|
||||
environment: { type: 'string', required: false },
|
||||
indexName: { type: 'string', required: false },
|
||||
indexHost: { type: 'string', required: false },
|
||||
namespace: { type: 'string', required: false },
|
||||
// Generate embeddings inputs
|
||||
@@ -210,6 +256,9 @@ export const PineconeBlock: BlockConfig<PineconeResponse> = {
|
||||
rerank: { type: 'json', required: false },
|
||||
// Fetch inputs
|
||||
ids: { type: 'json', required: false },
|
||||
vector: { type: 'json', required: false },
|
||||
includeValues: { type: 'boolean', required: false },
|
||||
includeMetadata: { type: 'boolean', required: false },
|
||||
},
|
||||
|
||||
outputs: {
|
||||
|
||||
@@ -81,7 +81,9 @@ export const TagDropdown: React.FC<TagDropdownProps> = ({
|
||||
// First check for evaluator metrics
|
||||
if (sourceBlock.type === 'evaluator') {
|
||||
try {
|
||||
const metricsValue = sourceBlock.subBlocks?.metrics?.value as unknown as Metric[]
|
||||
const metricsValue = useSubBlockStore
|
||||
.getState()
|
||||
.getValue(activeSourceBlockId, 'metrics') as unknown as Metric[]
|
||||
if (Array.isArray(metricsValue)) {
|
||||
return {
|
||||
tags: metricsValue.map(
|
||||
@@ -148,7 +150,9 @@ export const TagDropdown: React.FC<TagDropdownProps> = ({
|
||||
|
||||
if (sourceBlock.type === 'evaluator') {
|
||||
try {
|
||||
const metricsValue = sourceBlock.subBlocks?.metrics?.value as unknown as Metric[]
|
||||
const metricsValue = useSubBlockStore
|
||||
.getState()
|
||||
.getValue(edge.source, 'metrics') as unknown as Metric[]
|
||||
if (Array.isArray(metricsValue)) {
|
||||
return metricsValue.map(
|
||||
(metric) => `${normalizedBlockName}.response.${metric.name.toLowerCase()}`
|
||||
|
||||
@@ -21,6 +21,7 @@ import { embeddingsTool as openAIEmbeddings } from './openai/embeddings'
|
||||
import { fetchTool as pineconeFetchTool } from './pinecone/fetch'
|
||||
import { generateEmbeddingsTool as pineconeGenerateEmbeddingsTool } from './pinecone/generate'
|
||||
import { searchTextTool as pineconeSearchTextTool } from './pinecone/searchText'
|
||||
import { searchVectorTool as pineconeSearchVectorTool } from './pinecone/searchVector'
|
||||
import { upsertTextTool as pineconeUpsertTextTool } from './pinecone/upsertText'
|
||||
import { opportunitiesTool as salesforceOpportunities } from './salesforce/opportunities'
|
||||
import { searchTool as serperSearch } from './serper/search'
|
||||
@@ -69,6 +70,7 @@ export const tools: Record<string, ToolConfig> = {
|
||||
pinecone_fetch: pineconeFetchTool,
|
||||
pinecone_generate_embeddings: pineconeGenerateEmbeddingsTool,
|
||||
pinecone_search_text: pineconeSearchTextTool,
|
||||
pinecone_search_vector: pineconeSearchVectorTool,
|
||||
pinecone_upsert_text: pineconeUpsertTextTool,
|
||||
github_pr: prTool,
|
||||
github_comment: commentTool,
|
||||
|
||||
78
tools/pinecone/searchVector.ts
Normal file
78
tools/pinecone/searchVector.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { ToolConfig } from '../types'
|
||||
import { PineconeResponse, PineconeSearchVectorParams } from './types'
|
||||
|
||||
export const searchVectorTool: ToolConfig<PineconeSearchVectorParams, PineconeResponse> = {
|
||||
id: 'pinecone_search_vector',
|
||||
name: 'Pinecone Search Vector',
|
||||
description: 'Search for similar vectors in a Pinecone index',
|
||||
version: '1.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
requiredForToolCall: true,
|
||||
description: 'Pinecone API key',
|
||||
},
|
||||
indexHost: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
requiredForToolCall: true,
|
||||
description: 'Full Pinecone index host URL',
|
||||
},
|
||||
namespace: { type: 'string', required: false, description: 'Namespace to search in' },
|
||||
vector: { type: 'array', required: true, description: 'Vector to search for' },
|
||||
topK: { type: 'number', required: false, description: 'Number of results to return' },
|
||||
filter: { type: 'object', required: false, description: 'Filter to apply to the search' },
|
||||
includeValues: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
description: 'Include vector values in response',
|
||||
},
|
||||
includeMetadata: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
description: 'Include metadata in response',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: (params) => `${params.indexHost}/query`,
|
||||
headers: (params) => ({
|
||||
'Api-Key': params.apiKey,
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
namespace: params.namespace,
|
||||
vector: typeof params.vector === 'string' ? JSON.parse(params.vector) : params.vector,
|
||||
topK: params.topK ? parseInt(params.topK.toString()) : 10,
|
||||
filter: params.filter
|
||||
? typeof params.filter === 'string'
|
||||
? JSON.parse(params.filter)
|
||||
: params.filter
|
||||
: undefined,
|
||||
includeValues: true, //TODO: Make this dynamic
|
||||
includeMetadata: true, //TODO: Make this dynamic
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response) => {
|
||||
const data = await response.json()
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
matches: data.matches.map((match: any) => ({
|
||||
id: match.id,
|
||||
score: match.score,
|
||||
values: match.values,
|
||||
metadata: match.metadata,
|
||||
})),
|
||||
namespace: data.namespace,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error) => `Pinecone vector search failed: ${error.message}`,
|
||||
}
|
||||
@@ -150,3 +150,12 @@ export interface PineconeParams {
|
||||
metadata?: Record<string, any>
|
||||
}>
|
||||
}
|
||||
|
||||
// Search Vector
|
||||
export interface PineconeSearchVectorParams extends PineconeBaseParams {
|
||||
vector: number[] | string
|
||||
topK?: number | string
|
||||
filter?: Record<string, any> | string
|
||||
includeValues?: boolean
|
||||
includeMetadata?: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user