File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
src/store/src/Bridge/Postgres Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,20 @@ public function add(VectorDocument ...$documents): void
92
92
*/
93
93
public function query (Vector $ vector , array $ options = []): array
94
94
{
95
+ $ where = null ;
96
+
95
97
$ maxScore = $ options ['maxScore ' ] ?? null ;
98
+ if ($ maxScore ) {
99
+ $ where = "WHERE ( {$ this ->vectorFieldName } {$ this ->distance ->getComparisonSign ()} :embedding) <= :maxScore " ;
100
+ }
101
+
102
+ if ($ options ['where ' ] ?? false ) {
103
+ if ($ where ) {
104
+ $ where .= ' AND ( ' .$ options ['where ' ].') ' ;
105
+ } else {
106
+ $ where = 'WHERE ' .$ options ['where ' ];
107
+ }
108
+ }
96
109
97
110
$ sql = \sprintf (<<<SQL
98
111
SELECT id, %s AS embedding, metadata, (%s %s :embedding) AS score
@@ -105,13 +118,14 @@ public function query(Vector $vector, array $options = []): array
105
118
$ this ->vectorFieldName ,
106
119
$ this ->distance ->getComparisonSign (),
107
120
$ this ->tableName ,
108
- null !== $ maxScore ? " WHERE ( { $ this -> vectorFieldName } { $ this -> distance -> getComparisonSign ()} :embedding) <= :maxScore " : '' ,
121
+ $ where ?? '' ,
109
122
$ options ['limit ' ] ?? 5 ,
110
123
);
111
124
$ statement = $ this ->connection ->prepare ($ sql );
112
125
113
126
$ params = [
114
127
'embedding ' => $ this ->toPgvector ($ vector ),
128
+ ...$ options ['params ' ] ?? [],
115
129
];
116
130
if (null !== $ maxScore ) {
117
131
$ params ['maxScore ' ] = $ maxScore ;
You can’t perform that action at this time.
0 commit comments