vector_search
Perform nearest-neighbor search on PostgreSQL vector columns by embedding query text and ranking with pgvector. Supports hybrid fusion with lexical search.
Instructions
Nearest-neighbor search. Embeds each query string and ranks with pgvector. query is an array: one element runs one search; multiple elements run the same search (same table, where, columns, limit) once per element and return grouped results. Pass text_column to fuse each ranking with a lexical list using reciprocal rank fusion (k=60). lexical=fts (default) uses English full text: stems, drops stop words, keeps Arabic, and drops query terms that appear in more than 40% of rows. lexical=trgm uses pg_trgm word_similarity above pg_trgm.word_similarity_threshold. Omit text_column for dense search only. A where clause sets hnsw.iterative_scan=strict_order for that query. hnsw.ef_search is raised when the candidate limit is above 40. Default payload omits embedding and *hash. include_scores defaults to true and adds distance, plus rrf, dense_rank, and lexical_rank when hybrid. Set include_scores false to omit those columns. response_format=markdown returns one markdown table per query element.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Max rows (default 10, max 100) | |
| query | Yes | Search strings (max 20). One element searches that text. Multiple elements each return their own group, tagged Results for {text}. A single string is accepted as one element. | |
| table | Yes | Table name | |
| where | No | SQL WHERE fragment applied before ranking (no WHERE keyword) | |
| metric | No | cosine (default), l2, or ip. Must match the HNSW opclass to use the index. | |
| schema | No | Schema (default: public) | |
| columns | No | Payload columns. Omit for all except embedding and *hash. | |
| lexical | No | fts (default) or trgm. Requires text_column. fts for passages. trgm for short names that have a trigram index. | |
| text_column | No | Text column for hybrid search. Use the passage column for fts, or the short name column for trgm. Omit for dense search only. | |
| include_scores | No | Default true. When false, omit distance, and omit rrf, dense_rank, and lexical_rank on hybrid search. Ranking is unchanged. | |
| response_format | No | Empty for JSON. "markdown" returns one table per query element, headed Results for {text}, using the same columns as the JSON rows. | |
| embedding_column | Yes | vector or halfvec column |