mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
feat(memory): modified pinecone tools, adjusted pinecone block
This commit is contained in:
+8
-4
@@ -17,8 +17,10 @@ import { notionWriteTool } from './notion/write'
|
||||
import { chatTool as openAIChat } from './openai/chat'
|
||||
import { embeddingsTool as openAIEmbeddings } from './openai/embeddings'
|
||||
import { deleteTool as pineconeDeleteTool } from './pinecone/delete'
|
||||
import { queryTool as pineconeQueryTool } from './pinecone/query'
|
||||
import { upsertTool as pineconeUpsertTool } from './pinecone/upsert'
|
||||
import { fetchTool as pineconeFetchTool } from './pinecone/fetch'
|
||||
import { generateEmbeddingsTool as pineconeGenerateEmbeddingsTool } from './pinecone/generate'
|
||||
import { searchTextTool as pineconeSearchTextTool } from './pinecone/searchText'
|
||||
import { upsertTextTool as pineconeUpsertTextTool } from './pinecone/upsertText'
|
||||
import { opportunitiesTool as salesforceOpportunities } from './salesforce/opportunities'
|
||||
import { searchTool as serperSearch } from './serper/search'
|
||||
import { slackMessageTool } from './slack/message'
|
||||
@@ -63,9 +65,11 @@ export const tools: Record<string, ToolConfig> = {
|
||||
x_read: xRead,
|
||||
x_search: xSearch,
|
||||
x_user: xUser,
|
||||
pinecone_query: pineconeQueryTool,
|
||||
pinecone_upsert: pineconeUpsertTool,
|
||||
pinecone_delete: pineconeDeleteTool,
|
||||
pinecone_fetch: pineconeFetchTool,
|
||||
pinecone_generate_embeddings: pineconeGenerateEmbeddingsTool,
|
||||
pinecone_search_text: pineconeSearchTextTool,
|
||||
pinecone_upsert_text: pineconeUpsertTextTool,
|
||||
}
|
||||
|
||||
// Get a tool by its ID
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { ToolConfig } from '../types'
|
||||
import { PineconeFetchParams, PineconeResponse } from './types'
|
||||
|
||||
export const fetchTool: ToolConfig<PineconeFetchParams, PineconeResponse> = {
|
||||
id: 'pinecone_fetch',
|
||||
name: 'Pinecone Fetch',
|
||||
description: 'Fetch vectors by ID from a Pinecone index',
|
||||
version: '1.0',
|
||||
|
||||
params: {
|
||||
apiKey: { type: 'string', required: true, description: 'Pinecone API key' },
|
||||
environment: { type: 'string', required: true, description: 'Pinecone environment' },
|
||||
indexName: { type: 'string', required: true, description: 'Name of the Pinecone index' },
|
||||
ids: { type: 'array', required: true, description: 'Array of vector IDs to fetch' },
|
||||
namespace: { type: 'string', required: false, description: 'Namespace to fetch vectors from' },
|
||||
},
|
||||
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: (params) => {
|
||||
const baseUrl = `https://${params.indexName}-${params.environment}.svc.${params.environment}.pinecone.io/vectors/fetch`
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('ids', params.ids.join(','))
|
||||
if (params.namespace) {
|
||||
queryParams.append('namespace', params.namespace)
|
||||
}
|
||||
return `${baseUrl}?${queryParams.toString()}`
|
||||
},
|
||||
headers: (params) => ({
|
||||
'Api-Key': params.apiKey,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response) => {
|
||||
const data = await response.json()
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
matches: Object.entries(data.vectors).map(([id, vector]: [string, any]) => ({
|
||||
id,
|
||||
score: 1.0, // Fetch doesn't return scores, so we use 1.0 for exact matches
|
||||
values: vector.values,
|
||||
metadata: vector.metadata,
|
||||
})),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error) => `Pinecone fetch failed: ${error.message}`,
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { ToolConfig } from '../types'
|
||||
import { PineconeGenerateEmbeddingsParams, PineconeResponse } from './types'
|
||||
|
||||
export const generateEmbeddingsTool: ToolConfig<
|
||||
PineconeGenerateEmbeddingsParams,
|
||||
PineconeResponse
|
||||
> = {
|
||||
id: 'pinecone_generate_embeddings',
|
||||
name: 'Pinecone Generate Embeddings',
|
||||
description: "Generate embeddings from text using Pinecone's hosted models",
|
||||
version: '1.0',
|
||||
|
||||
params: {
|
||||
apiKey: { type: 'string', required: true, description: 'Pinecone API key' },
|
||||
environment: { type: 'string', required: true, description: 'Pinecone environment' },
|
||||
indexName: { type: 'string', required: true, description: 'Name of the Pinecone index' },
|
||||
model: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Model to use for generating embeddings',
|
||||
},
|
||||
inputs: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
description: 'Array of text inputs to generate embeddings for',
|
||||
},
|
||||
parameters: { type: 'object', required: false, description: 'Additional model parameters' },
|
||||
},
|
||||
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: () => 'https://api.pinecone.io/embed',
|
||||
headers: (params) => ({
|
||||
'Api-Key': params.apiKey,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Pinecone-API-Version': '2025-01',
|
||||
}),
|
||||
body: (params) => ({
|
||||
model: params.model,
|
||||
inputs: params.inputs,
|
||||
parameters: {
|
||||
input_type: 'passage',
|
||||
truncate: 'END',
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response) => {
|
||||
const data = await response.json()
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
embeddings: data.embeddings,
|
||||
usage: data.usage,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error) => `Pinecone embeddings generation failed: ${error.message}`,
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
import { ToolConfig } from '../types'
|
||||
import { PineconeParams, PineconeResponse } from './types'
|
||||
|
||||
export const queryTool: ToolConfig<PineconeParams, PineconeResponse> = {
|
||||
id: 'pinecone_query',
|
||||
name: 'Pinecone Query',
|
||||
description: 'Query vectors from Pinecone index',
|
||||
version: '1.0',
|
||||
|
||||
params: {
|
||||
apiKey: { type: 'string', required: true, description: 'Pinecone API key' },
|
||||
environment: { type: 'string', required: true, description: 'Pinecone environment' },
|
||||
indexName: { type: 'string', required: true, description: 'Name of the Pinecone index' },
|
||||
queryVector: { type: 'array', required: true, description: 'Vector to query' },
|
||||
topK: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
default: 10,
|
||||
description: 'Number of results to return',
|
||||
},
|
||||
includeMetadata: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: true,
|
||||
description: 'Include metadata in results',
|
||||
},
|
||||
includeValues: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
default: false,
|
||||
description: 'Include vector values in results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: (params) =>
|
||||
`https://${params.indexName}-${params.environment}.svc.${params.environment}.pinecone.io/vectors/query`,
|
||||
headers: (params) => ({
|
||||
'Api-Key': params.apiKey,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
vector: params.queryVector,
|
||||
topK: params.topK || 10,
|
||||
includeMetadata: params.includeMetadata ?? true,
|
||||
includeValues: params.includeValues ?? false,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response) => {
|
||||
const data = await response.json()
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
matches: data.matches || [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error) => `Pinecone query failed: ${error.message}`,
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { ToolConfig } from '../types'
|
||||
import { PineconeResponse, PineconeSearchTextParams } from './types'
|
||||
|
||||
export const searchTextTool: ToolConfig<PineconeSearchTextParams, PineconeResponse> = {
|
||||
id: 'pinecone_search_text',
|
||||
name: 'Pinecone Search Text',
|
||||
description: 'Search for similar text in a Pinecone index',
|
||||
version: '1.0',
|
||||
|
||||
params: {
|
||||
apiKey: { type: 'string', required: true, description: 'Pinecone API key' },
|
||||
environment: { type: 'string', required: true, description: 'Pinecone environment' },
|
||||
indexName: { type: 'string', required: true, description: 'Name of the Pinecone index' },
|
||||
namespace: { type: 'string', required: false, description: 'Namespace to search in' },
|
||||
query: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: 'Query parameters including text input and top_k',
|
||||
},
|
||||
fields: {
|
||||
type: 'array',
|
||||
required: false,
|
||||
description: 'Fields to return in the search results',
|
||||
},
|
||||
rerank: {
|
||||
type: 'object',
|
||||
required: false,
|
||||
description: 'Parameters for reranking the initial search results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: (params) =>
|
||||
`https://${params.indexName}-${params.environment}.svc.${params.environment}.pinecone.io/records/namespaces/${params.namespace || ''}/search`,
|
||||
headers: (params) => ({
|
||||
'Api-Key': params.apiKey,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
query: params.query,
|
||||
fields: params.fields,
|
||||
rerank: params.rerank,
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response) => {
|
||||
const data = await response.json()
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
matches: data.matches.map((match: any) => ({
|
||||
id: match.id,
|
||||
score: match.score,
|
||||
metadata: match.metadata,
|
||||
values: match.values,
|
||||
})),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error) => `Pinecone text search failed: ${error.message}`,
|
||||
}
|
||||
+83
-13
@@ -1,5 +1,88 @@
|
||||
import { ToolResponse } from '../types'
|
||||
|
||||
// Base Pinecone params shared across all operations
|
||||
export interface PineconeBaseParams {
|
||||
apiKey: string
|
||||
environment: string
|
||||
indexName: string
|
||||
}
|
||||
|
||||
// Response types
|
||||
export interface PineconeMatchResponse {
|
||||
id: string
|
||||
score: number
|
||||
values?: number[]
|
||||
metadata?: Record<string, any>
|
||||
}
|
||||
|
||||
export interface PineconeResponse extends ToolResponse {
|
||||
output: {
|
||||
matches?: PineconeMatchResponse[]
|
||||
upsertedCount?: number
|
||||
deletedCount?: number
|
||||
embeddings?: number[][]
|
||||
usage?: {
|
||||
prompt_tokens: number
|
||||
total_tokens: number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate Embeddings
|
||||
export interface PineconeGenerateEmbeddingsParams extends PineconeBaseParams {
|
||||
model: string
|
||||
inputs: { text: string }[]
|
||||
parameters?: Record<string, any>
|
||||
}
|
||||
|
||||
// Upsert Text
|
||||
export interface PineconeUpsertTextParams extends PineconeBaseParams {
|
||||
namespace?: string
|
||||
records: {
|
||||
_id: string
|
||||
text: string
|
||||
metadata?: Record<string, any>
|
||||
}[]
|
||||
}
|
||||
|
||||
// Upsert Vectors
|
||||
export interface PineconeUpsertVectorsParams extends PineconeBaseParams {
|
||||
namespace?: string
|
||||
vectors: {
|
||||
id: string
|
||||
values: number[]
|
||||
metadata?: Record<string, any>
|
||||
sparseValues?: {
|
||||
indices: number[]
|
||||
values: number[]
|
||||
}
|
||||
}[]
|
||||
}
|
||||
|
||||
// Search Text
|
||||
export interface PineconeSearchTextParams extends PineconeBaseParams {
|
||||
namespace?: string
|
||||
query: {
|
||||
inputs: string
|
||||
top_k: number
|
||||
filter?: Record<string, any>
|
||||
}
|
||||
fields?: string[]
|
||||
rerank?: {
|
||||
model: string
|
||||
rank_fields: string[]
|
||||
top_n?: number
|
||||
parameters?: Record<string, any>
|
||||
query?: string
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch Vectors
|
||||
export interface PineconeFetchParams extends PineconeBaseParams {
|
||||
ids: string[]
|
||||
namespace?: string
|
||||
}
|
||||
|
||||
export interface PineconeParams {
|
||||
apiKey: string
|
||||
environment: string
|
||||
@@ -20,16 +103,3 @@ export interface PineconeParams {
|
||||
ids?: string[]
|
||||
deleteAll?: boolean
|
||||
}
|
||||
|
||||
export interface PineconeResponse extends ToolResponse {
|
||||
output: {
|
||||
matches?: Array<{
|
||||
id: string
|
||||
score: number
|
||||
values?: number[]
|
||||
metadata?: Record<string, any>
|
||||
}>
|
||||
upsertedCount?: number
|
||||
deletedCount?: number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
import { ToolConfig } from '../types'
|
||||
import { PineconeParams, PineconeResponse } from './types'
|
||||
import { PineconeResponse, PineconeUpsertTextParams } from './types'
|
||||
|
||||
export const upsertTool: ToolConfig<PineconeParams, PineconeResponse> = {
|
||||
id: 'pinecone_upsert',
|
||||
name: 'Pinecone Upsert',
|
||||
description: 'Upsert vectors into Pinecone index',
|
||||
export const upsertTextTool: ToolConfig<PineconeUpsertTextParams, PineconeResponse> = {
|
||||
id: 'pinecone_upsert_text',
|
||||
name: 'Pinecone Upsert Text',
|
||||
description: 'Insert or update text records in a Pinecone index',
|
||||
version: '1.0',
|
||||
|
||||
params: {
|
||||
apiKey: { type: 'string', required: true, description: 'Pinecone API key' },
|
||||
environment: { type: 'string', required: true, description: 'Pinecone environment' },
|
||||
indexName: { type: 'string', required: true, description: 'Name of the Pinecone index' },
|
||||
vectors: {
|
||||
namespace: { type: 'string', required: false, description: 'Namespace to upsert records into' },
|
||||
records: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
description: 'Array of vectors to upsert, each with id, values, and optional metadata',
|
||||
description: 'Array of records to upsert, each containing _id, text, and optional metadata',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: (params) =>
|
||||
`https://${params.indexName}-${params.environment}.svc.${params.environment}.pinecone.io/vectors/upsert`,
|
||||
`https://${params.indexName}-${params.environment}.svc.${params.environment}.pinecone.io/records/namespaces/${params.namespace || ''}/upsert`,
|
||||
headers: (params) => ({
|
||||
'Api-Key': params.apiKey,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params) => ({
|
||||
vectors: params.vectors,
|
||||
records: params.records,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -41,5 +42,5 @@ export const upsertTool: ToolConfig<PineconeParams, PineconeResponse> = {
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error) => `Pinecone upsert failed: ${error.message}`,
|
||||
transformError: (error) => `Pinecone text upsert failed: ${error.message}`,
|
||||
}
|
||||
Reference in New Issue
Block a user