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

[Couchbase VectorStore] Add RecordManager #3397

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions packages/components/credentials/CouchbaseApi.credential.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* Temporary disabled due to the incompatibility with the docker node-alpine:
* https://github.com/FlowiseAI/Flowise/pull/2303
import { INodeParams, INodeCredential } from '../src/Interface'

class CouchbaseApi implements INodeCredential {
Expand Down Expand Up @@ -36,4 +32,3 @@ class CouchbaseApi implements INodeCredential {
}

module.exports = { credClass: CouchbaseApi }
*/
38 changes: 31 additions & 7 deletions packages/components/nodes/vectorstores/Couchbase/Couchbase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* Temporary disabled due to the incompatibility with the docker node-alpine:
* https://github.com/FlowiseAI/Flowise/pull/2303

import { flatten } from 'lodash'
import { Embeddings } from '@langchain/core/embeddings'
import { Document } from '@langchain/core/documents'
Expand All @@ -10,6 +6,7 @@ import { Cluster } from 'couchbase'
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { resolveVectorStoreOrRetriever } from '../VectorStoreUtils'
import { index } from '../../../src/indexing'

class Couchbase_VectorStores implements INode {
label: string
Expand Down Expand Up @@ -53,6 +50,13 @@ class Couchbase_VectorStores implements INode {
name: 'embeddings',
type: 'Embeddings'
},
{
label: 'Record Manager',
name: 'recordManager',
type: 'RecordManager',
description: 'Keep track of the record to prevent duplication',
optional: true
},
{
label: 'Bucket Name',
name: 'bucketName',
Expand Down Expand Up @@ -143,6 +147,7 @@ class Couchbase_VectorStores implements INode {
let databasePassword = getCredentialParam('password', credentialData, nodeData)

const docs = nodeData.inputs?.document as Document[]
const recordManager = nodeData.inputs?.recordManager

const flattenDocs = docs && docs.length ? flatten(docs) : []
const finalDocs = []
Expand Down Expand Up @@ -173,8 +178,28 @@ class Couchbase_VectorStores implements INode {
if (!textKey || textKey === '') couchbaseConfig.textKey = 'text'
if (!embeddingKey || embeddingKey === '') couchbaseConfig.embeddingKey = 'embedding'

await CouchbaseVectorStore.fromDocuments(finalDocs, embeddings, couchbaseConfig)
return { numAdded: finalDocs.length, addedDocs: finalDocs }
if (recordManager) {
const vectorStore = await CouchbaseVectorStore.initialize(embeddings, couchbaseConfig)

await recordManager.createSchema()

const res = await index({
docsSource: finalDocs,
recordManager,
vectorStore,
options: {
cleanup: recordManager?.cleanup,
sourceIdKey: recordManager?.sourceIdKey ?? 'source',
vectorStoreName: [bucketName, scopeName, indexName].join('_')
}
})

return res
} else {
await CouchbaseVectorStore.fromDocuments(finalDocs, embeddings, couchbaseConfig)

return { numAdded: finalDocs.length, addedDocs: finalDocs }
}
} catch (e) {
throw new Error(e)
}
Expand Down Expand Up @@ -231,4 +256,3 @@ class Couchbase_VectorStores implements INode {
}

module.exports = { nodeClass: Couchbase_VectorStores }
*/
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"cheerio": "^1.0.0-rc.12",
"chromadb": "^1.5.11",
"cohere-ai": "^7.7.5",
"couchbase": "4.4.1",
"crypto-js": "^4.1.1",
"css-what": "^6.1.0",
"d3-dsv": "2",
Expand Down
Loading