Merge pull request #1677 from fletch-ai/bugfix/Postgres-SSL-Fix

Fixing Postgres so that similaritySearchVectorWithScore actually connects via TLS/SSL when specified
This commit is contained in:
Henry Heng
2024-02-10 22:10:36 +08:00
committed by GitHub
@@ -24,7 +24,7 @@ class Postgres_VectorStores implements INode {
constructor() { constructor() {
this.label = 'Postgres' this.label = 'Postgres'
this.name = 'postgres' this.name = 'postgres'
this.version = 2.0 this.version = 3.0
this.type = 'Postgres' this.type = 'Postgres'
this.icon = 'postgres.svg' this.icon = 'postgres.svg'
this.category = 'Vector Stores' this.category = 'Vector Stores'
@@ -60,13 +60,6 @@ class Postgres_VectorStores implements INode {
name: 'database', name: 'database',
type: 'string' type: 'string'
}, },
{
label: 'SSL Connection',
name: 'sslConnection',
type: 'boolean',
default: false,
optional: false
},
{ {
label: 'Port', label: 'Port',
name: 'port', name: 'port',
@@ -124,7 +117,6 @@ class Postgres_VectorStores implements INode {
const docs = nodeData.inputs?.document as Document[] const docs = nodeData.inputs?.document as Document[]
const embeddings = nodeData.inputs?.embeddings as Embeddings const embeddings = nodeData.inputs?.embeddings as Embeddings
const additionalConfig = nodeData.inputs?.additionalConfig as string const additionalConfig = nodeData.inputs?.additionalConfig as string
const sslConnection = nodeData.inputs?.sslConnection as boolean
let additionalConfiguration = {} let additionalConfiguration = {}
if (additionalConfig) { if (additionalConfig) {
@@ -142,8 +134,7 @@ class Postgres_VectorStores implements INode {
port: nodeData.inputs?.port as number, port: nodeData.inputs?.port as number,
username: user, username: user,
password: password, password: password,
database: nodeData.inputs?.database as string, database: nodeData.inputs?.database as string
ssl: sslConnection
} }
const args = { const args = {
@@ -198,7 +189,8 @@ class Postgres_VectorStores implements INode {
type: 'postgres', type: 'postgres',
host: nodeData.inputs?.host as string, host: nodeData.inputs?.host as string,
port: nodeData.inputs?.port as number, port: nodeData.inputs?.port as number,
username: user, username: user, // Required by TypeORMVectorStore
user: user, // Required by Pool in similaritySearchVectorWithScore
password: password, password: password,
database: nodeData.inputs?.database as string database: nodeData.inputs?.database as string
} }
@@ -248,14 +240,7 @@ const similaritySearchVectorWithScore = async (
ORDER BY "_distance" ASC ORDER BY "_distance" ASC
LIMIT $3;` LIMIT $3;`
const poolOptions = { const pool = new Pool(postgresConnectionOptions)
host: postgresConnectionOptions.host,
port: postgresConnectionOptions.port,
user: postgresConnectionOptions.username,
password: postgresConnectionOptions.password,
database: postgresConnectionOptions.database
}
const pool = new Pool(poolOptions)
const conn = await pool.connect() const conn = await pool.connect()
const documents = await conn.query(queryString, [embeddingString, _filter, k]) const documents = await conn.query(queryString, [embeddingString, _filter, k])