Documents

Search Documents

Search your database using text or images. Vecstore performs semantic search across text-to-text, image-to-image, and text-to-image, returning the most relevant documents ranked by similarity.

POST/databases/{id}/search
Database type

Request

Replace {id} in the path with your database ID and send a JSON body like this one.

Example request
{
  "content": "kitchen faucet repair",
  "metadata": {
    "category": "home-repair"
  },
  "top_k": 10,
  "page": 1,
  "per_page": 5,
  "min_score": 0.3
}

Query ·optional

Without a query, documents are listed newest first.

content string
Text to search for

Filters ·optional

metadata object
Only return documents with these metadata values. Metadata Filters
min_score number
Drop results scoring below this, between 0 and 1. Filtering by Score
mode string
hybrid (default), semantic or keyword. Search Modes

Pagination ·optional

top_k integer
Most results you can page through, up to 1000. Defaults to 10
page integer
Which page to return
per_page integer
Results per page, up to 100. Defaults to top_k

Facets ·optional

facets string[]
Metadata keys to count values for, up to 20. Facets
max_facet_values integer
Values returned per facet, up to 100. Defaults to 10
facet_depth integer
Results that facets are counted over. With a query: top-ranked results, up to 1000, defaulting to 100 or top_k if larger. Without one: matching documents, up to 50,000, defaulting to 10,000

Response

Returns a page of results, best match first.

Example response
{
  "results": [
    {
      "id": "4de5bed5-e483-4bd7-9760-a54ec07aefd9",
      "content": "How to fix a leaky kitchen faucet",
      "metadata": {
        "category": "home-repair"
      },
      "score": 0.92
    },
    {
      "id": "7f8e9a0b-1c2d-3e4f-5a6b-7c8d9e0f1a2b",
      "content": "Replacing a kitchen sink tap",
      "metadata": {
        "category": "plumbing"
      },
      "score": 0.87
    }
  ],
  "page": 1,
  "per_page": 5,
  "estimated_total": 10,
  "has_more": true,
  "search_time": "4ms",
  "embedding_ms": 9.8
}

Each result

id string
Document ID
content string | null
Document text. null for images
metadata object | null
Metadata stored with the document
score float
Higher is better. Between 0 and 1, except in keyword mode

Paging and timing

page integer
Current page
per_page integer
Results per page
has_more boolean
Whether another page exists
estimated_total integer
Approximate result count. Exact on the last page
total integer
Exact count. Replaces estimated_total in filtered searches without a query that match fewer than 10,000 documents
search_time string
Time spent on the database query
embedding_ms float
Time spent embedding the query. Omitted in metadata-only searches

Facets

Only returned when the request includes facets.

facets object
Value counts for each requested key, most common first
facet_stats object
min, max and avg for keys with numeric values
facets_exhaustive boolean
true if every match was counted, false if counting stopped at facet_depth

Search Modes

Text databases support three ways of matching a content query, set with mode. Every mode costs 1 credit per search. Modes apply to text databases. Image databases always use semantic search.

hybrid
Default. Matches both meaning and exact terms. The best choice for most search bars.
semantic
Meaning only. Good for paraphrased queries and searching across languages.
keyword
Exact words only (BM25), no embedding. Good for product codes, names and IDs. Scores have no upper bound, so min_score is rejected.
Example: keyword search
{
  "content": "SKU-48213",
  "mode": "keyword",
  "top_k": 10
}

Pagination

top_k caps how many results you can page through, and per_page sets how many come back per request. The first page of a top_k of 1000 is as fast as a top_k of 10; later pages cost more. Keep raising page while has_more is true.

Example: 10 results per page, up to 100
{
  "content": "running shoes",
  "top_k": 100,
  "page": 1,
  "per_page": 10
}

Metadata Filters

Match a field to one value, to any value in a list with $in, or to a numeric range. All of them can be combined in one request, and a document must match every field.

Example: equality + $in + range
"metadata": {
  "category": "shoes",
  "brand": { "$in": ["nike", "salomon"] },
  "price": { "$gte": 50, "$lte": 150 }
}

Operators

value
Equal to this value, e.g. "category": "shoes"
$in
Equal to any value in the list, e.g. "brand": { "$in": ["nike", "hoka"] }
$gt / $gte
Greater than / greater than or equal to a number
$lt / $lte
Less than / less than or equal to a number

Matching rules

  • Fields stored as arrays match if any element matches, so "color": "black" finds documents with "color": ["black", "red"].
  • Values are compared by type after converting text that looks like a number or boolean, so "42" matches 42 and "true" matches true.
  • Ranges only match numbers. Documents where the field is text, missing or null are left out. On arrays, one element must satisfy every bound.
  • $in takes up to 1000 strings, numbers or booleans. Empty lists are rejected.
  • Unknown operators and non-numeric bounds return 400. Keys must match [a-zA-Z0-9_-]{1,64}.

Tip: equality and $in filters use an index, ranges don't. In a metadata-only search, add at least one equality filter next to a range on large databases, so the range only checks the documents that already match.

Facets

List metadata keys in facets to get a count of each value across your results, for building filter sidebars like brand, color or size. Counts cover the top top_k results on every page, not just the page returned, so they match exactly what a user can page through. Facets cost no extra credits.

Example request
{
  "content": "trail running shoes",
  "metadata": { "in_stock": true },
  "facets": ["brand", "color", "price"],
  "max_facet_values": 5,
  "top_k": 200,
  "per_page": 20
}
Example response
{
  "results": [
    {
      "id": "4de5bed5-e483-4bd7-9760-a54ec07aefd9",
      "content": "Salomon Speedcross 6 trail running shoe",
      "metadata": {
        "brand": "salomon",
        "color": ["black", "red"],
        "price": 139.99,
        "in_stock": true
      },
      "score": 0.97
    }
  ],
  "page": 1,
  "per_page": 20,
  "estimated_total": 200,
  "has_more": true,
  "facets": {
    "brand": { "salomon": 74, "nike": 61, "hoka": 38 },
    "color": { "black": 88, "grey": 51, "blue": 34, "red": 29, "green": 12 },
    "price": { "129.99": 21, "139.99": 17, "99.99": 15, "159": 12, "119": 9 }
  },
  "facet_stats": {
    "price": { "min": 59.99, "max": 249.0, "avg": 132.4 }
  },
  "facets_exhaustive": true,
  "search_time": "12ms",
  "embedding_ms": 9.8
}

How values are counted

  • Each document counts once per value. For arrays, every distinct element counts, so a shoe in sizes [42, 43] adds 1 to both.
  • Strings, numbers and booleans are counted. Nested objects and null are skipped.
  • Values come back as strings, most common first, ties in alphabetical order. Send one back as a metadata filter as-is: "42" matches the number 42.
  • Every requested key appears in facets, as {} if no result has it. facet_stats only lists keys with numeric values.

Facets with filters

Facets are counted after metadata filters, so filtering on brand leaves only the selected brands in the brand counts. To keep showing every option for a facet while it's selected, send a second request without that filter and read its counts.

Facets for the whole database

Leave out the query to count values across every document, or send only a metadata filter to count across the documents that match it. Up to facet_depth documents are counted, 10,000 by default. Past that, facets_exhaustive is false:

  • Without a filter, counts come from a random sample and are scaled up to the size of the database. Rare values can be missing.
  • With a filter, counts cover the first facet_depth matching documents.
Example: facets for the whole database
{
  "facets": ["brand", "color", "price"],
  "per_page": 20
}

Note: with a query, every page searches the full top_k, so keep top_k as small as your UI needs. Keys must match [a-zA-Z0-9_-]{1,64}.

Find Similar

Send a document's ID as similar_to in place of a query to find documents like it. The stored embedding is reused, so the search is faster, and the source document is left out of the results. Works on text and image databases, with or without a metadata filter. Returns 404 if the ID doesn't exist.

Example request
{
  "similar_to":"4de5bed5-e483-4bd7-9760-a54ec07aefd9",
  "top_k": 10
}

Metadata-Only Search FREE

Leave out content, image, image_url and similar_to to filter by metadata alone. No embedding or vector search runs, so no credit is charged. Every score is 0.0, and you get an exact total instead of estimated_total.

Example request
{
  "metadata": {
    "type": "variant",
    "product_id": { "$in": [321, 123] }
  },
  "page": 1,
  "per_page": 20
}

Filtering by Score

Set min_score to drop weak matches instead of always getting top_k results. Low scores are removed before pagination, so fewer results may come back. It has no effect on metadata-only searches and returns 400 in keyword mode.

SearchScoreGood starting point
Text → imageCalibrated, 0 to 10.3
Image → imageCosine similarity0.6
Text → text, hybrid1.0 if ranked first by both–
Text → text, semanticCosine similarity–