File tree Expand file tree Collapse file tree 2 files changed +16
-14
lines changed
packages/components/nodes/vectorstores/Postgres/driver Expand file tree Collapse file tree 2 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -75,11 +75,12 @@ export class PGVectorDriver extends VectorStoreDriver {
75
75
76
76
// @ts -ignore
77
77
instance . pool . query = ( queryString : string , parameters : any [ ] ) => {
78
- // Tweak query to handle $notexists
78
+ // Match chatflow uploaded file and keep filtering on other files:
79
+ // https://github.com/FlowiseAI/Flowise/pull/3367#discussion_r1804229295
79
80
if ( $notexists ) {
80
- const chatClause = ` ${ instance . metadataColumnName } ->>' ${ $notexists } ' = $ ${
81
- parameters . length + 1
82
- } OR NOT (metadata ? '${ $notexists } ')`
81
+ parameters . push ( { [ $notexists ] : chatId } )
82
+
83
+ const chatClause = `metadata @> $ ${ parameters . length } OR NOT (metadata ? '${ $notexists } ')`
83
84
const whereClauseRegex = / W H E R E ( [ ^ \n ] + ) /
84
85
if ( queryString . match ( whereClauseRegex ) ) {
85
86
queryString = queryString . replace ( whereClauseRegex , `WHERE $1 AND (${ chatClause } )` )
@@ -94,8 +95,6 @@ export class PGVectorDriver extends VectorStoreDriver {
94
95
`
95
96
)
96
97
}
97
-
98
- parameters . push ( chatId )
99
98
}
100
99
101
100
// Run base function
Original file line number Diff line number Diff line change @@ -113,14 +113,17 @@ export class TypeORMDriver extends VectorStoreDriver {
113
113
filter ?: any
114
114
) => {
115
115
const embeddingString = `[${ query . join ( ',' ) } ]`
116
- let _filter = '{}'
117
116
let notExists = ''
118
- if ( filter && typeof filter === 'object' ) {
119
- if ( filter . $notexists ) {
120
- notExists = `OR NOT (metadata ? '${ filter . $notexists } ')`
121
- delete filter . $notexists
122
- }
123
- _filter = JSON . stringify ( filter )
117
+ const { $notexists, [ $notexists ] : chatId , ...restFilters } = filter || { }
118
+
119
+ const _filter = JSON . stringify ( restFilters || { } )
120
+ const parameters : any [ ] = [ embeddingString , _filter , k ]
121
+
122
+ // Match chatflow uploaded file and keep filtering on other files:
123
+ // https://github.com/FlowiseAI/Flowise/pull/3367#discussion_r1804229295
124
+ if ( $notexists ) {
125
+ parameters . push ( { [ $notexists ] : chatId } )
126
+ notExists = `AND (metadata @> $${ parameters . length } OR NOT (metadata ? '${ $notexists } '))`
124
127
}
125
128
126
129
const queryString = `
@@ -135,7 +138,7 @@ export class TypeORMDriver extends VectorStoreDriver {
135
138
136
139
const conn = await pool . connect ( )
137
140
138
- const documents = await conn . query ( queryString , [ embeddingString , _filter , k ] )
141
+ const documents = await conn . query ( queryString , parameters )
139
142
140
143
conn . release ( )
141
144
You can’t perform that action at this time.
0 commit comments