Skip to main content
Version: Latest (v2.4)

Search Functionality

๐ŸŽ“ For a practical walkthrough, see the: Amazon S3 Vectors with Spice engineering blog post.

Spice provides comprehensive search capabilities enabling developers to query datasets beyond traditional SQL, including semantic (vector-based) search, full-text keyword search, and hybrid search methods.

Search Methods Overviewโ€‹

Spice supports multiple search methods:

  • Vector Search: Semantic search using embeddings to retrieve data by meaning and similarity.
  • Multi-Vector Search: Search over columns of vectors, including ColBERT-style late-interaction queries.
  • Full-Text Search: Keyword-driven search optimized for text data retrieval.
  • Hybrid Search: Combine multiple search methods using Reciprocal Rank Fusion (RRF) for improved relevance.
  • Reranking: Reorder search results using dedicated reranker models or LLM-as-reranker for improved relevance.
  • SQL Search: Traditional SQL queries for precise and structured searches.

Vector search uses embeddingsโ€”numerical representations of dataโ€”to identify similar or related content based on semantic meaning.

Requirements:

  • Configured data connectors or accelerators
  • Defined embeddings for datasets

Getting Started:

Example SQL Vector Search:

SELECT id, extra_column, _score
FROM vector_search(my_table, 'search query')
WHERE date_published > '2021-01-01'
ORDER BY _score DESC
LIMIT 5;

For complete SQL UDTF specifications, see Vector-Based Search SQL UDTF.

Multi-vector search operates on columns that store many vectors per row, such as per-tag or per-section embeddings. It also supports ColBERT-style late-interaction queries where the query itself is an array of strings.

Requirements:

  • A list-typed source column (List<Utf8>) embedded with a multi-vector aggregation

Getting Started:

Example SQL Multi-Vector Search:

SELECT product_id, name, _score
FROM vector_search(products, ['hiking', 'waterproof'], tags)
ORDER BY _score DESC
LIMIT 10;

Full-text search efficiently retrieves records matching specific keywords.

Requirements:

  • Indexed columns within datasets

Getting Started:

Example SQL Full-Text Search:

SELECT id, extra_column, _score
FROM text_search(my_table, 'search terms')
WHERE date_published > '2021-01-01'
ORDER BY _score DESC
LIMIT 5;

For detailed SQL UDTF instructions, see Full-Text Search SQL UDTF.

Hybrid Search with RRFโ€‹

Reciprocal Rank Fusion (RRF) combines results by merging rankings from multiple search methods to improve relevance. This is useful when neither vector search nor full-text search alone provides optimal results.

Requirements:

  • Multiple search methods configured (vector, full-text, etc.)

When to use hybrid search:

  • The query contains both semantic concepts and specific keywords.
  • Results from a single method are missing relevant documents.
  • Improved ranking is needed across diverse content types.

Example SQL Hybrid Search:

SELECT id, title, content, fused_score
FROM rrf(
vector_search(documents, 'machine learning algorithms'),
text_search(documents, 'neural networks deep learning', content),
join_key => 'id' -- join key for optimal performance
)
ORDER BY fused_score DESC
LIMIT 5;

For complete RRF syntax and parameters, see Search SQL Reference.

Rerankingโ€‹

Reranking reorders search results using a dedicated reranker model (Cohere, Voyage, Jina, or a custom HTTP endpoint), any registered chat model as an LLM-as-reranker, or a decision model such as TypeSafe Jev. This two-stage retrieve-then-rerank pattern improves relevance beyond initial retrieval scores.

Requirements:

  • A registered reranker (in the rerankers: spicepod section), chat model, or decision model

Getting Started:

Example SQL Rerank:

SELECT * FROM rerank(
rrf(
vector_search(docs, 'delta lake time travel', limit => 50),
text_search(docs, 'delta lake time travel', limit => 50)
),
document => 'content',
model => 'cohere_rr',
limit => 10
);

For complete rerank syntax and parameters, see Search SQL Reference.

Where indexes are builtโ€‹

Build full-text and vector indexes on the central acceleration tier, and let application sidecars answer repeats from the search results cache (runtime.caching.search_results). The in-memory full-text index is rebuilt on every start; a file-backed one is a separate directory and is not part of an acceleration snapshot. A DuckDB HNSW index lives in the DuckDB file, so it travels with that file's snapshot. See Cluster-Sidecar.

Search Results and Dataset Refreshโ€‹

POST /v1/search results are stored in the search results cache (runtime.caching.search_results), and an accelerated refresh of a dataset evicts them. A SQL query that calls text_search or vector_search is stored in the SQL results cache (runtime.caching.sql_results) and follows its item_ttl, like other SQL. A refresh does not evict it, so it does not see the refresh until the entry expires: right after a refresh, /v1/search can return a new match while the same search through /v1/sql returns the result cached before the refresh, as a HIT, for up to item_ttl. See Cached Results and Dataset Refresh.

To read a search's current results through SQL, send the request with Cache-Control: no-cache, or set item_ttl to how long a search result may be served after a refresh. rrf and rerank results are never stored in the SQL results cache, so they always read the current data.

Dataset Readinessโ€‹

An accelerated dataset cannot be searched until its initial load completes. With the default ready_state: on_load, searching a dataset that is still loading fails with the same error a SQL query returns:

Acceleration not ready; loading initial data for <dataset_name>

This applies to every search method โ€” vector search (whether served just-in-time or from a vector index) and full-text search โ€” so a partially-loaded index never answers with the subset that happens to have loaded so far.

When a search request does not name any datasets and instead sweeps every searchable dataset, a dataset that is not ready is excluded from the results rather than failing the whole request. Naming that dataset explicitly returns the error above.

Datasets configured ready_state: on_registration or ready_state: on_schema_resolved are unaffected: they remain searchable while the accelerator loads, served from the federated source. Datasets accelerated with refresh_mode: caching are also exempt, as they serve queries without an initial load.

Cookbookโ€‹