33 *
44 * Auto-discovers all `vector` columns across all tables and adds:
55 *
6- * 1. **vectorSearch<TableType>** query fields on Query
7- * - Accepts a query vector, metric, limit, offset
8- * - Returns rows ordered by distance with a `distance` score
9- *
10- * 2. **<column>Nearby** condition fields on connection condition inputs
6+ * 1. **<column>Nearby** filter fields on connection filter inputs
117 * - Accepts { vector, metric?, distance? } to filter by distance threshold
128 * - Computes distance server-side using pgvector operators
9+ * - Lives inside the `filter` argument (via postgraphile-plugin-connection-filter)
1310 *
14- * 3 . **<column>Distance** computed fields on output types
15- * - Returns the distance value when a nearby condition is active (null otherwise)
11+ * 2 . **<column>Distance** computed fields on output types
12+ * - Returns the distance value when a nearby filter is active (null otherwise)
1613 *
17- * 4 . **<COLUMN>_DISTANCE_ASC/DESC** orderBy enum values
18- * - Orders results by vector distance when a nearby condition is active
14+ * 3 . **<COLUMN>_DISTANCE_ASC/DESC** orderBy enum values
15+ * - Orders results by vector distance when a nearby filter is active
1916 *
2017 * Uses the Grafast meta system (setMeta/getMeta) to pass data between
21- * the condition apply phase and the output field plan, following the
18+ * the filter apply phase and the output field plan, following the
2219 * pattern from Benjie's postgraphile-plugin-fulltext-filter reference.
2320 *
24- * Follows the same patterns as graphile-search- plugin (for tsvector columns) .
21+ * Requires postgraphile- plugin-connection-filter to be loaded first .
2522 */
2623
2724import 'graphile-build' ;
@@ -133,17 +130,19 @@ export function createVectorSearchPlugin(
133130 const {
134131 defaultMetric = 'COSINE' ,
135132 maxLimit = 100 ,
136- conditionPrefix = 'vector' ,
133+ filterPrefix = 'vector' ,
137134 } = options ;
138135
139136 return {
140137 name : 'VectorSearchPlugin' ,
141138 version : '1.0.0' ,
142139 description :
143- 'Auto-discovers vector columns and adds search fields, conditions , and orderBy' ,
140+ 'Auto-discovers vector columns and adds filter fields, distance computed fields , and orderBy' ,
144141 after : [
145142 'VectorCodecPlugin' ,
146143 'PgAttributesPlugin' ,
144+ 'PgConnectionArgFilterPlugin' ,
145+ 'PgConnectionArgFilterAttributesPlugin' ,
147146 ] ,
148147
149148 // ─── Custom Inflection Methods ─────────────────────────────────────
@@ -454,18 +453,23 @@ export function createVectorSearchPlugin(
454453 } ,
455454
456455 /**
457- * Add `<column>Nearby` condition fields on connection condition input types
456+ * Add `<column>Nearby` filter fields on connection filter input types
458457 * for tables with vector columns.
458+ *
459+ * Uses the connection filter plugin's `isPgConnectionFilter` scope.
460+ * The apply function receives a PgCondition wrapping PgSelectStep,
461+ * identical to the condition approach — so we can use the same
462+ * getQueryBuilder() traversal for selectAndReturnIndex/setMeta/orderBy.
459463 */
460464 GraphQLInputObjectType_fields ( fields , build , context ) {
461465 const { inflection, sql } = build ;
462466 const {
463- scope : { isPgCondition , pgCodec } ,
467+ scope : { isPgConnectionFilter , pgCodec } = { } as any ,
464468 fieldWithHooks,
465469 } = context ;
466470
467471 if (
468- ! isPgCondition ||
472+ ! isPgConnectionFilter ||
469473 ! pgCodec ||
470474 ! pgCodec . attributes ||
471475 pgCodec . isAnonymous
@@ -487,7 +491,7 @@ export function createVectorSearchPlugin(
487491
488492 for ( const [ attributeName ] of vectorAttributes ) {
489493 const fieldName = inflection . camelCase (
490- `${ conditionPrefix } _${ attributeName } `
494+ `${ filterPrefix } _${ attributeName } `
491495 ) ;
492496 const baseFieldName = inflection . attribute ( {
493497 codec : pgCodec as any ,
@@ -501,8 +505,8 @@ export function createVectorSearchPlugin(
501505 [ fieldName ] : fieldWithHooks (
502506 {
503507 fieldName,
504- isPgConnectionConditionInputField : true ,
505- } ,
508+ isPgConnectionFilterField : true ,
509+ } as any ,
506510 {
507511 description : build . wrapDescription (
508512 `Vector similarity search on the \`${ attributeName } \` column. ` +
@@ -583,7 +587,7 @@ export function createVectorSearchPlugin(
583587 }
584588 ) ,
585589 } ,
586- `VectorSearchPlugin adding condition field '${ fieldName } ' for vector column '${ attributeName } ' on '${ pgCodec . name } '`
590+ `VectorSearchPlugin adding filter field '${ fieldName } ' for vector column '${ attributeName } ' on '${ pgCodec . name } '`
587591 ) ;
588592 }
589593
0 commit comments