Retrieve with context
retrieve_with_contextRun pgvector k-NN search and expand each hit one hop through foreign keys, returning the matching row plus related parent and child records in one call.
Instructions
Context-packed k-NN retrieval (a one-shot RAG building block). Runs a pgvector k-NN against schema.table.embedding_column for a caller-supplied query_vector (no embedding model needed), then expands each hit one hop along foreign keys and returns the hit row + its related parent / child records in one object. Parents (when include_parents, default true) are the rows a hit references via outbound FKs; children (when include_children, default true) are rows referencing the hit via inbound FKs, capped at max_related (default 5) per FK. Limitations: 1 hop only; inbound (child) expansion is same-schema only. The embedding column is dropped from every returned row. Requires the vector extension. Returns available, dimension, detail, and hits (each with distance, row, and related — a list of fk_name/direction/related_schema/related_table/rows).
Example: retrieve_with_context(schema='public', table='docs', embedding_column='embedding', query_vector=[0.1, 0.2, 0.3], k=5)
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"schema": "<schema>",
"table": "<table>",
"embedding_column": "<embedding_column>",
"query_vector": "<query_vector>"
},
"name": "retrieve_with_context"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| k | No | ||
| table | Yes | ||
| metric | No | l2 | |
| schema | Yes | ||
| database | No | Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected. | |
| max_related | No | ||
| query_vector | Yes | ||
| include_parents | No | ||
| embedding_column | Yes | ||
| include_children | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hits | Yes | ||
| detail | No | ||
| available | Yes | ||
| dimension | Yes |