Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Add Text Key to Pinecone #2681

Merged
merged 7 commits into from
Jun 19, 2024
Merged
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
50 changes: 37 additions & 13 deletions packages/components/nodes/vectorstores/Pinecone/Pinecone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { flatten } from 'lodash'
import { Pinecone } from '@pinecone-database/pinecone'
import { flatten, isEqual } from 'lodash'
import { Pinecone, PineconeConfiguration } from '@pinecone-database/pinecone'
import { PineconeStoreParams, PineconeStore } from '@langchain/pinecone'
import { Embeddings } from '@langchain/core/embeddings'
import { Document } from '@langchain/core/documents'
Expand All @@ -8,6 +8,23 @@ import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../
import { addMMRInputParams, resolveVectorStoreOrRetriever } from '../VectorStoreUtils'
import { index } from '../../../src/indexing'

let pineconeClientSingleton: Pinecone
let pineconeClientOption: PineconeConfiguration

const getPineconeClient = (option: PineconeConfiguration) => {
if (!pineconeClientSingleton) {
// if client doesn't exists
pineconeClientSingleton = new Pinecone(option)
pineconeClientOption = option
return pineconeClientSingleton
} else if (pineconeClientSingleton && !isEqual(option, pineconeClientOption)) {
// if client exists but option changed
pineconeClientSingleton = new Pinecone(option)
return pineconeClientSingleton
}
return pineconeClientSingleton
}

class Pinecone_VectorStores implements INode {
label: string
name: string
Expand All @@ -25,7 +42,7 @@ class Pinecone_VectorStores implements INode {
constructor() {
this.label = 'Pinecone'
this.name = 'pinecone'
this.version = 3.0
this.version = 4.0
this.type = 'Pinecone'
this.icon = 'pinecone.svg'
this.category = 'Vector Stores'
Expand Down Expand Up @@ -71,6 +88,15 @@ class Pinecone_VectorStores implements INode {
additionalParams: true,
optional: true
},
{
label: 'Pinecone Text Key',
name: 'pineconeTextKey',
description: 'The key in the metadata for storing text. Default to `text`',
type: 'string',
placeholder: 'text',
additionalParams: true,
optional: true
},
{
label: 'Pinecone Metadata Filter',
name: 'pineconeMetadataFilter',
Expand Down Expand Up @@ -111,13 +137,12 @@ class Pinecone_VectorStores implements INode {
const docs = nodeData.inputs?.document as Document[]
const embeddings = nodeData.inputs?.embeddings as Embeddings
const recordManager = nodeData.inputs?.recordManager
const pineconeTextKey = nodeData.inputs?.pineconeTextKey as string

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const pineconeApiKey = getCredentialParam('pineconeApiKey', credentialData, nodeData)

const client = new Pinecone({
apiKey: pineconeApiKey
})
const client = getPineconeClient({ apiKey: pineconeApiKey })

const pineconeIndex = client.Index(_index)

Expand All @@ -130,7 +155,8 @@ class Pinecone_VectorStores implements INode {
}

const obj: PineconeStoreParams = {
pineconeIndex
pineconeIndex,
textKey: pineconeTextKey ?? 'text'
}

if (pineconeNamespace) obj.namespace = pineconeNamespace
Expand Down Expand Up @@ -166,20 +192,18 @@ class Pinecone_VectorStores implements INode {
const pineconeNamespace = nodeData.inputs?.pineconeNamespace as string
const pineconeMetadataFilter = nodeData.inputs?.pineconeMetadataFilter
const embeddings = nodeData.inputs?.embeddings as Embeddings
const pineconeTextKey = nodeData.inputs?.pineconeTextKey as string

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const pineconeApiKey = getCredentialParam('pineconeApiKey', credentialData, nodeData)

const client = new Pinecone({
apiKey: pineconeApiKey
})

await client.describeIndex(index)
const client = getPineconeClient({ apiKey: pineconeApiKey })

const pineconeIndex = client.Index(index)

const obj: PineconeStoreParams = {
pineconeIndex
pineconeIndex,
textKey: pineconeTextKey ?? 'text'
}

if (pineconeNamespace) obj.namespace = pineconeNamespace
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@mistralai/mistralai": "0.1.3",
"@notionhq/client": "^2.2.8",
"@opensearch-project/opensearch": "^1.2.0",
"@pinecone-database/pinecone": "2.2.0",
"@pinecone-database/pinecone": "2.2.2",
"@qdrant/js-client-rest": "^1.2.2",
"@supabase/supabase-js": "^2.29.0",
"@types/js-yaml": "^4.0.5",
Expand Down
Loading
Loading