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

[Prostgres Vector Store] Add PGVector Driver option + Fix null character issue w/ TypeORM Driver #3367

Merged
Show file tree
Hide file tree
Changes from 11 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
14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,19 @@ Flowise support different environment variables to configure your instance. You
| S3_ENDPOINT_URL | Custom Endpoint for S3 | String | |
| S3_FORCE_PATH_STYLE | Set this to true to force the request to use path-style addressing | Boolean | false |
| SHOW_COMMUNITY_NODES | Show nodes created by community | Boolean | |

| POSTGRES_VECTORSTORE_HOST | Default `host` for Postgres Vector Store | String | |
| POSTGRES_VECTORSTORE_PORT | Default `port` for Postgres Vector Store | Number | 5432 |
| POSTGRES_VECTORSTORE_USER | Default `user` for Postgres Vector Store | String | |
| POSTGRES_VECTORSTORE_PASSWORD | Default `password` for Postgres Vector Store | String | |
| POSTGRES_VECTORSTORE_DATABASE | Default `database` for Postgres Vector Store | String | |
| POSTGRES_VECTORSTORE_TABLE_NAME | Default `tableName` for Postgres Vector Store | String | documents |
| POSTGRES_VECTORSTORE_CONTENT_COLUMN_NAME | Default `contentColumnName` for Postgres Vector Store | String | pageContent |
| POSTGRES_RECORDMANAGER_HOST | Default `host` for Postgres Record Manager | String | |
| POSTGRES_RECORDMANAGER_PORT | Default `port` for Postgres Record Manager | Number | 5432 |
| POSTGRES_RECORDMANAGER_USER | Default `user` for Postgres Record Manager | String | |
| POSTGRES_RECORDMANAGER_PASSWORD | Default `password` for Postgres Record Manager | String | |
| POSTGRES_RECORDMANAGER_DATABASE | Default `database` for Postgres Record Manager | String | |
| POSTGRES_RECORDMANAGER_TABLE_NAME | Default `tableName` for Postgres Record Manager | String | upsertion_records |
You can also specify the env variables when using `npx`. For example:

```
Expand Down
36 changes: 35 additions & 1 deletion docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,38 @@ BLOB_STORAGE_PATH=/root/.flowise/storage
# S3_FORCE_PATH_STYLE=false

# APIKEY_STORAGE_TYPE=json (json | db)
# SHOW_COMMUNITY_NODES=true
# SHOW_COMMUNITY_NODES=true

############################################
# Default postgres vectorstore credentials #
############################################

# POSTGRES_VECTORSTORE_USER=
# POSTGRES_VECTORSTORE_PASSWORD=

#######################################
# Default postgres vectorstore config #
#######################################

# POSTGRES_VECTORSTORE_HOST=
# POSTGRES_VECTORSTORE_DATABASE=
# POSTGRES_VECTORSTORE_PORT=
# POSTGRES_VECTORSTORE_TABLE_NAME=
# POSTGRES_VECTORSTORE_CONTENT_COLUMN_NAME=

###############################################
# Default postgres record manager credentials #
###############################################

# POSTGRES_RECORDMANAGER_USER=
# POSTGRES_RECORDMANAGER_PASSWORD=

##########################################
# Default postgres record manager config #
##########################################

# POSTGRES_RECORDMANAGER_HOST=
# POSTGRES_RECORDMANAGER_DATABASE=
# POSTGRES_RECORDMANAGER_PORT=
# POSTGRES_RECORDMANAGER_TABLE_NAME=
# POSTGRES_RECORDMANAGER_CONTENT_COLUMN_NAME=
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ListKeyOptions, RecordManagerInterface, UpdateOptions } from '@langchain/community/indexes/base'
import { DataSource, QueryRunner } from 'typeorm'
import { getHost } from '../../vectorstores/Postgres/utils'
import { getDatabase, getPort, getTableName } from './utils'

const serverCredentialsExists = !!process.env.POSTGRES_RECORDMANAGER_USER && !!process.env.POSTGRES_RECORDMANAGER_PASSWORD

class PostgresRecordManager_RecordManager implements INode {
label: string
Expand Down Expand Up @@ -29,18 +33,22 @@ class PostgresRecordManager_RecordManager implements INode {
{
label: 'Host',
name: 'host',
type: 'string'
type: 'string',
placeholder: getHost(),
optional: !!getHost()
},
{
label: 'Database',
name: 'database',
type: 'string'
type: 'string',
placeholder: getDatabase(),
optional: !!getDatabase()
},
{
label: 'Port',
name: 'port',
type: 'number',
placeholder: '5432',
placeholder: getPort(),
optional: true
},
{
Expand All @@ -54,7 +62,7 @@ class PostgresRecordManager_RecordManager implements INode {
label: 'Table Name',
name: 'tableName',
type: 'string',
placeholder: 'upsertion_records',
placeholder: getTableName(),
additionalParams: true,
optional: true
},
Expand Down Expand Up @@ -110,16 +118,16 @@ class PostgresRecordManager_RecordManager implements INode {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['PostgresApi']
credentialNames: ['PostgresApi'],
optional: serverCredentialsExists
}
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const user = getCredentialParam('user', credentialData, nodeData)
const password = getCredentialParam('password', credentialData, nodeData)
const _tableName = nodeData.inputs?.tableName as string
const tableName = _tableName ? _tableName : 'upsertion_records'
const user = getCredentialParam('user', credentialData, nodeData, process.env.POSTGRES_RECORDMANAGER_USER)
const password = getCredentialParam('password', credentialData, nodeData, process.env.POSTGRES_RECORDMANAGER_PASSWORD)
const tableName = getTableName(nodeData)
const additionalConfig = nodeData.inputs?.additionalConfig as string
const _namespace = nodeData.inputs?.namespace as string
const namespace = _namespace ? _namespace : options.chatflowid
Expand All @@ -139,11 +147,11 @@ class PostgresRecordManager_RecordManager implements INode {
const postgresConnectionOptions = {
...additionalConfiguration,
type: 'postgres',
host: nodeData.inputs?.host as string,
port: nodeData.inputs?.port as number,
host: getHost(nodeData),
port: getPort(nodeData),
username: user,
password: password,
database: nodeData.inputs?.database as string
database: getDatabase(nodeData)
}

const args = {
Expand All @@ -162,7 +170,7 @@ class PostgresRecordManager_RecordManager implements INode {

type PostgresRecordManagerOptions = {
postgresConnectionOptions: any
tableName?: string
tableName: string
}

class PostgresRecordManager implements RecordManagerInterface {
Expand All @@ -180,7 +188,7 @@ class PostgresRecordManager implements RecordManagerInterface {
const { postgresConnectionOptions, tableName } = config
this.namespace = namespace
this.datasource = new DataSource(postgresConnectionOptions)
this.tableName = tableName || 'upsertion_records'
this.tableName = tableName
}

async createSchema(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defaultChain, INodeData } from '../../../src'

export function getHost(nodeData?: INodeData) {
return defaultChain(nodeData?.inputs?.host, process.env.POSTGRES_RECORDMANAGER_HOST)
}

export function getDatabase(nodeData?: INodeData) {
return defaultChain(nodeData?.inputs?.database, process.env.POSTGRES_RECORDMANAGER_DATABASE)
}

export function getPort(nodeData?: INodeData) {
return defaultChain(nodeData?.inputs?.port, process.env.POSTGRES_RECORDMANAGER_PORT, '5432')
}

export function getTableName(nodeData?: INodeData) {
return defaultChain(nodeData?.inputs?.tableName, process.env.POSTGRES_RECORDMANAGER_TABLE_NAME, 'upsertion_records')
}
Loading