Skip to content

Commit 15d59a9

Browse files
JJK801HenryHengZJ
andauthored
[Prostgres Vector Store] Add PGVector Driver option + Fix null character issue w/ TypeORM Driver (#3367)
* Add PGVector Driver option + Fix null character issue w/ TypeORM Driver * Handle file upload case with PGVector * Cleanup * Fix data filtering for chatflow uploaded files * Add distanceStrategy parameter * Fix query to improve chatflow uploaded files filtering * Ensure PGVector release connections * Await client connected * Make Postgres credentials optionnal when set on env variables * Document env variables in nodes directories * Prevent reuse client * Fix empty metadataFilter * Update CONTRIBUTING.md * Update Postgres.ts --------- Co-authored-by: Henry Heng <[email protected]>
1 parent 39380a4 commit 15d59a9

File tree

10 files changed

+535
-204
lines changed

10 files changed

+535
-204
lines changed

packages/components/nodes/recordmanager/PostgresRecordManager/PostgresRecordManager.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
22
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
33
import { ListKeyOptions, RecordManagerInterface, UpdateOptions } from '@langchain/community/indexes/base'
44
import { DataSource, QueryRunner } from 'typeorm'
5+
import { getHost } from '../../vectorstores/Postgres/utils'
6+
import { getDatabase, getPort, getTableName } from './utils'
7+
8+
const serverCredentialsExists = !!process.env.POSTGRES_RECORDMANAGER_USER && !!process.env.POSTGRES_RECORDMANAGER_PASSWORD
59

610
class PostgresRecordManager_RecordManager implements INode {
711
label: string
@@ -29,18 +33,22 @@ class PostgresRecordManager_RecordManager implements INode {
2933
{
3034
label: 'Host',
3135
name: 'host',
32-
type: 'string'
36+
type: 'string',
37+
placeholder: getHost(),
38+
optional: !!getHost()
3339
},
3440
{
3541
label: 'Database',
3642
name: 'database',
37-
type: 'string'
43+
type: 'string',
44+
placeholder: getDatabase(),
45+
optional: !!getDatabase()
3846
},
3947
{
4048
label: 'Port',
4149
name: 'port',
4250
type: 'number',
43-
placeholder: '5432',
51+
placeholder: getPort(),
4452
optional: true
4553
},
4654
{
@@ -54,7 +62,7 @@ class PostgresRecordManager_RecordManager implements INode {
5462
label: 'Table Name',
5563
name: 'tableName',
5664
type: 'string',
57-
placeholder: 'upsertion_records',
65+
placeholder: getTableName(),
5866
additionalParams: true,
5967
optional: true
6068
},
@@ -110,16 +118,16 @@ class PostgresRecordManager_RecordManager implements INode {
110118
label: 'Connect Credential',
111119
name: 'credential',
112120
type: 'credential',
113-
credentialNames: ['PostgresApi']
121+
credentialNames: ['PostgresApi'],
122+
optional: serverCredentialsExists
114123
}
115124
}
116125

117126
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
118127
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
119-
const user = getCredentialParam('user', credentialData, nodeData)
120-
const password = getCredentialParam('password', credentialData, nodeData)
121-
const _tableName = nodeData.inputs?.tableName as string
122-
const tableName = _tableName ? _tableName : 'upsertion_records'
128+
const user = getCredentialParam('user', credentialData, nodeData, process.env.POSTGRES_RECORDMANAGER_USER)
129+
const password = getCredentialParam('password', credentialData, nodeData, process.env.POSTGRES_RECORDMANAGER_PASSWORD)
130+
const tableName = getTableName(nodeData)
123131
const additionalConfig = nodeData.inputs?.additionalConfig as string
124132
const _namespace = nodeData.inputs?.namespace as string
125133
const namespace = _namespace ? _namespace : options.chatflowid
@@ -139,11 +147,11 @@ class PostgresRecordManager_RecordManager implements INode {
139147
const postgresConnectionOptions = {
140148
...additionalConfiguration,
141149
type: 'postgres',
142-
host: nodeData.inputs?.host as string,
143-
port: nodeData.inputs?.port as number,
150+
host: getHost(nodeData),
151+
port: getPort(nodeData),
144152
username: user,
145153
password: password,
146-
database: nodeData.inputs?.database as string
154+
database: getDatabase(nodeData)
147155
}
148156

149157
const args = {
@@ -162,7 +170,7 @@ class PostgresRecordManager_RecordManager implements INode {
162170

163171
type PostgresRecordManagerOptions = {
164172
postgresConnectionOptions: any
165-
tableName?: string
173+
tableName: string
166174
}
167175

168176
class PostgresRecordManager implements RecordManagerInterface {
@@ -180,7 +188,7 @@ class PostgresRecordManager implements RecordManagerInterface {
180188
const { postgresConnectionOptions, tableName } = config
181189
this.namespace = namespace
182190
this.datasource = new DataSource(postgresConnectionOptions)
183-
this.tableName = tableName || 'upsertion_records'
191+
this.tableName = tableName
184192
}
185193

186194
async createSchema(): Promise<void> {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Postgres Record Manager
2+
3+
Postgres Record Manager integration for Flowise
4+
5+
## 🌱 Env Variables
6+
7+
| Variable | Description | Type | Default |
8+
| ---------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
9+
| POSTGRES_RECORDMANAGER_HOST | Default `host` for Postgres Record Manager | String | |
10+
| POSTGRES_RECORDMANAGER_PORT | Default `port` for Postgres Record Manager | Number | 5432 |
11+
| POSTGRES_RECORDMANAGER_USER | Default `user` for Postgres Record Manager | String | |
12+
| POSTGRES_RECORDMANAGER_PASSWORD | Default `password` for Postgres Record Manager | String | |
13+
| POSTGRES_RECORDMANAGER_DATABASE | Default `database` for Postgres Record Manager | String | |
14+
| POSTGRES_RECORDMANAGER_TABLE_NAME | Default `tableName` for Postgres Record Manager | String | upsertion_records |
15+
16+
## License
17+
18+
Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defaultChain, INodeData } from '../../../src'
2+
3+
export function getHost(nodeData?: INodeData) {
4+
return defaultChain(nodeData?.inputs?.host, process.env.POSTGRES_RECORDMANAGER_HOST)
5+
}
6+
7+
export function getDatabase(nodeData?: INodeData) {
8+
return defaultChain(nodeData?.inputs?.database, process.env.POSTGRES_RECORDMANAGER_DATABASE)
9+
}
10+
11+
export function getPort(nodeData?: INodeData) {
12+
return defaultChain(nodeData?.inputs?.port, process.env.POSTGRES_RECORDMANAGER_PORT, '5432')
13+
}
14+
15+
export function getTableName(nodeData?: INodeData) {
16+
return defaultChain(nodeData?.inputs?.tableName, process.env.POSTGRES_RECORDMANAGER_TABLE_NAME, 'upsertion_records')
17+
}

0 commit comments

Comments
 (0)