Skip to main content

Vector Search

The vector search endpoint provides typed, read-only pgvector similarity search brokered through the FoundryDB controller. It composes a single SELECT from validated inputs and executes it inside a READ ONLY transaction with a statement timeout and row cap. Your application never needs a direct database connection.

Vector search is available on PostgreSQL services only. The service must be in Running status.

How It Works

You send a POST request with a query vector (or text to embed server-side) and the name of the table and column to search. The controller validates all identifiers and parameters, then routes the query to the service's primary node via the agent. Results are returned synchronously, ordered by ascending distance.

Endpoints

POST /managed-services/{id}/vector-search

Authentication uses the same basic auth credentials as the rest of the platform API.

Request Body

FieldTypeRequiredDescription
tablestringYesTable containing the vector column.
database_namestringNoDatabase to query. Defaults to the engine default, or the pipeline's database when query_text is used.
schemastringNoSchema of the table. Defaults to public.
embedding_columnstringNoName of the vector column. Defaults to embedding.
vectorfloat[]Exactly one of vector or query_textQuery vector (max 8192 dimensions, all components must be finite).
query_textstringExactly one of vector or query_textText to embed server-side using the referenced pipeline. Requires pipeline_id. Max 8192 characters.
pipeline_idUUIDWhen using query_textEmbedding pipeline used to embed the text. Must belong to this service.
top_kintegerNoNumber of rows to return. Range 1-100. Defaults to 10.
metricstringNoDistance metric: cosine (default), l2, or ip.
filtersarrayNoEquality filters ANDed into the WHERE clause. Max 32 filters.
include_columnsstring[]NoColumns to return. Defaults to all columns. Max 100.

Filters

Each filter object requires:

{ "column": "category", "op": "eq", "value": "security" }

Only equality (eq) is supported. Values can be string, number, or boolean.

Distance Metrics

Valuepgvector OperatorUse When
cosine<=>Normalized embeddings, semantic similarity (most common).
l2<->Euclidean distance, un-normalized vectors.
ip<#>Inner product (negated), max-margin retrieval.

Response

{
"columns": [
{ "name": "id", "type": "int8" },
{ "name": "content", "type": "text" },
{ "name": "distance", "type": "float8" }
],
"rows": [
[42, "PostgreSQL supports TLS for all client connections.", 0.031]
],
"row_count": 1,
"truncated": false,
"execution_ms": 4,
"metric": "cosine",
"top_k": 10
}

A distance column is always appended to the selected columns. truncated is true if a row or byte cap cut the result short.

Example: Query with a Pre-Computed Vector

curl -u $USER:$PASS \
-X POST https://api.foundrydb.com/managed-services/$SERVICE_ID/vector-search \
-H "Content-Type: application/json" \
-d '{
"table": "articles_embeddings",
"embedding_column": "embedding",
"vector": [0.021, -0.134, 0.007],
"top_k": 5,
"metric": "cosine",
"include_columns": ["source_row_id", "text_content"],
"filters": [
{ "column": "category", "op": "eq", "value": "security" }
]
}'

Example: Query with Text (Server-Side Embedding)

When you provide query_text instead of vector, the controller embeds the text using the referenced pipeline's model and dimensions before running the search. This keeps embedding logic out of your application.

curl -u $USER:$PASS \
-X POST https://api.foundrydb.com/managed-services/$SERVICE_ID/vector-search \
-H "Content-Type: application/json" \
-d '{
"table": "articles_embeddings",
"query_text": "how to secure a database connection",
"pipeline_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"top_k": 5
}'

The pipeline_id must belong to this service. The embedding is produced using the same provider, model, and dimensions that created the indexed vectors, so distances are comparable.

Setting Up Your Table

The vector column must be created with the pgvector extension. An HNSW index on the column is strongly recommended for production use:

CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE articles_embeddings (
source_row_id BIGINT PRIMARY KEY,
text_content TEXT,
category TEXT,
embedding vector(1536)
);

CREATE INDEX ON articles_embeddings
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);

Error Codes

HTTP StatusMeaning
400Invalid request: wrong service type, missing table, unsupported metric, bad identifier, vector dimension mismatch, filter error, or embedding failure.
401Authentication required.
404Service not found, no VM instances, or referenced pipeline not found.
500Storage, encryption, or token-metering failure.

What's Next