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

Add singlestore upsert and existing #540

Merged
merged 5 commits into from
Jul 19, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"*.{js,jsx,ts,tsx,json,md}": "eslint --fix"
},
"devDependencies": {
"turbo": "1.7.4",
"@babel/preset-env": "^7.19.4",
"@babel/preset-typescript": "7.18.6",
"@types/express": "^4.17.13",
Expand All @@ -48,6 +47,7 @@
"pretty-quick": "^3.1.3",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"turbo": "1.7.4",
"typescript": "^4.8.4"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
import { Embeddings } from 'langchain/embeddings/base'
import { getBaseClasses } from '../../../src/utils'
import { SingleStoreVectorStore, SingleStoreVectorStoreConfig } from 'langchain/vectorstores/singlestore'

class SingleStoreExisting_VectorStores implements INode {
label: string
name: string
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
outputs: INodeOutputsValue[]

constructor() {
this.label = 'SingleStore Load Existing Table'
this.name = 'singlestoreExisting'
this.type = 'SingleStore'
this.icon = 'singlestore.svg'
this.category = 'Vector Stores'
this.description = 'Load existing document from SingleStore'
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
this.inputs = [
{
label: 'Embeddings',
name: 'embeddings',
type: 'Embeddings'
},
{
label: 'Host',
name: 'host',
type: 'string'
},
{
label: 'User',
name: 'user',
type: 'string'
},
{
label: 'Password',
name: 'password',
type: 'password'
},
{
label: 'Database',
name: 'database',
type: 'string'
},
{
label: 'Table Name',
name: 'tableName',
type: 'string',
placeholder: 'embeddings',
additionalParams: true,
optional: true
},
{
label: 'Content Column Name',
name: 'contentColumnName',
type: 'string',
placeholder: 'content',
additionalParams: true,
optional: true
},
{
label: 'Vector Column Name',
name: 'vectorColumnName',
type: 'string',
placeholder: 'vector',
additionalParams: true,
optional: true
},
{
label: 'Metadata Column Name',
name: 'metadataColumnName',
type: 'string',
placeholder: 'metadata',
additionalParams: true,
optional: true
},
{
label: 'Top K',
name: 'topK',
placeholder: '4',
type: 'number',
additionalParams: true,
optional: true
}
]
this.outputs = [
{
label: 'SingleStore Retriever',
name: 'retriever',
baseClasses: this.baseClasses
},
{
label: 'SingleStore Vector Store',
name: 'vectorStore',
baseClasses: [this.type, ...getBaseClasses(SingleStoreVectorStore)]
}
]
}

async init(nodeData: INodeData): Promise<any> {
const singleStoreConnectionConfig = {
connectionOptions: {
host: nodeData.inputs?.host as string,
port: 3306,
user: nodeData.inputs?.user as string,
password: nodeData.inputs?.password as string,
database: nodeData.inputs?.database as string
},
...(nodeData.inputs?.tableName ? { tableName: nodeData.inputs.tableName as string } : {}),
...(nodeData.inputs?.contentColumnName ? { contentColumnName: nodeData.inputs.contentColumnName as string } : {}),
...(nodeData.inputs?.vectorColumnName ? { vectorColumnName: nodeData.inputs.vectorColumnName as string } : {}),
...(nodeData.inputs?.metadataColumnName ? { metadataColumnName: nodeData.inputs.metadataColumnName as string } : {})
} as SingleStoreVectorStoreConfig

const embeddings = nodeData.inputs?.embeddings as Embeddings
const output = nodeData.outputs?.output as string
const topK = nodeData.inputs?.topK as string
const k = topK ? parseInt(topK, 10) : 4

let vectorStore: SingleStoreVectorStore

vectorStore = new SingleStoreVectorStore(embeddings, singleStoreConnectionConfig)

if (output === 'retriever') {
const retriever = vectorStore.asRetriever(k)
return retriever
} else if (output === 'vectorStore') {
;(vectorStore as any).k = k
return vectorStore
}
return vectorStore
}
}

module.exports = { nodeClass: SingleStoreExisting_VectorStores }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { INode, INodeData, INodeOutputsValue, INodeParams } from '../../../src/Interface'
import { Embeddings } from 'langchain/embeddings/base'
import { Document } from 'langchain/document'
import { getBaseClasses } from '../../../src/utils'
import { SingleStoreVectorStore, SingleStoreVectorStoreConfig } from 'langchain/vectorstores/singlestore'
import { flatten } from 'lodash'

class SingleStoreUpsert_VectorStores implements INode {
label: string
name: string
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
outputs: INodeOutputsValue[]

constructor() {
this.label = 'SingleStore Upsert Document'
this.name = 'singlestoreUpsert'
this.type = 'SingleStore'
this.icon = 'singlestore.svg'
this.category = 'Vector Stores'
this.description = 'Upsert documents to SingleStore'
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
this.inputs = [
{
label: 'Document',
name: 'document',
type: 'Document',
list: true
},
{
label: 'Embeddings',
name: 'embeddings',
type: 'Embeddings'
},
{
label: 'Host',
name: 'host',
type: 'string'
},
{
label: 'User',
name: 'user',
type: 'string'
},
{
label: 'Password',
name: 'password',
type: 'password'
},
{
label: 'Database',
name: 'database',
type: 'string'
},
{
label: 'Table Name',
name: 'tableName',
type: 'string',
placeholder: 'embeddings',
additionalParams: true,
optional: true
},
{
label: 'Content Column Name',
name: 'contentColumnName',
type: 'string',
placeholder: 'content',
additionalParams: true,
optional: true
},
{
label: 'Vector Column Name',
name: 'vectorColumnName',
type: 'string',
placeholder: 'vector',
additionalParams: true,
optional: true
},
{
label: 'Metadata Column Name',
name: 'metadataColumnName',
type: 'string',
placeholder: 'metadata',
additionalParams: true,
optional: true
},
{
label: 'Top K',
name: 'topK',
placeholder: '4',
type: 'number',
additionalParams: true,
optional: true
}
]
this.outputs = [
{
label: 'SingleStore Retriever',
name: 'retriever',
baseClasses: this.baseClasses
},
{
label: 'SingleStore Vector Store',
name: 'vectorStore',
baseClasses: [this.type, ...getBaseClasses(SingleStoreVectorStore)]
}
]
}

async init(nodeData: INodeData): Promise<any> {
const singleStoreConnectionConfig = {
connectionOptions: {
host: nodeData.inputs?.host as string,
port: 3306,
user: nodeData.inputs?.user as string,
password: nodeData.inputs?.password as string,
database: nodeData.inputs?.database as string
},
...(nodeData.inputs?.tableName ? { tableName: nodeData.inputs.tableName as string } : {}),
...(nodeData.inputs?.contentColumnName ? { contentColumnName: nodeData.inputs.contentColumnName as string } : {}),
...(nodeData.inputs?.vectorColumnName ? { vectorColumnName: nodeData.inputs.vectorColumnName as string } : {}),
...(nodeData.inputs?.metadataColumnName ? { metadataColumnName: nodeData.inputs.metadataColumnName as string } : {})
} as SingleStoreVectorStoreConfig

const docs = nodeData.inputs?.document as Document[]
const embeddings = nodeData.inputs?.embeddings as Embeddings
const output = nodeData.outputs?.output as string
const topK = nodeData.inputs?.topK as string
const k = topK ? parseInt(topK, 10) : 4

const flattenDocs = docs && docs.length ? flatten(docs) : []
const finalDocs = []
for (let i = 0; i < flattenDocs.length; i += 1) {
finalDocs.push(new Document(flattenDocs[i]))
}

let vectorStore: SingleStoreVectorStore

vectorStore = new SingleStoreVectorStore(embeddings, singleStoreConnectionConfig)
vectorStore.addDocuments.bind(vectorStore)(finalDocs)

if (output === 'retriever') {
const retriever = vectorStore.asRetriever(k)
return retriever
} else if (output === 'vectorStore') {
;(vectorStore as any).k = k
return vectorStore
}
return vectorStore
}
}

module.exports = { nodeClass: SingleStoreUpsert_VectorStores }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"srt-parser-2": "^1.2.3",
"vm2": "^3.9.19",
"weaviate-ts-client": "^1.1.0",
"ws": "^8.9.0"
"ws": "^8.9.0",
"mysql2": "^3.5.1"
},
"devDependencies": {
"@types/gulp": "4.0.9",
Expand Down