RAG & Agentic Retrieval

Spice runs vector, full-text, and hybrid search over data in databases, warehouses, data lakes, and APIs. One runtime ranks the results, passes them to a model for analysis and decisions, and serves them to agents as tools.

Diagram of apps and agents that call Spice.ai, which runs search, rank, and generate steps over a data store of S3 and MySQL and over models from OpenAI and Anthropic

Ground every answer in your data

RAG pipelines and AI agents get fresh, governed context from sources across your enterprise. Spice retrieves it, ranks it with hybrid search, and passes it to a model in one SQL query.

Retrieve from
every source

Query databases, warehouses, object stores, and APIs with federated SQL, with no ETL pipeline. Accelerate a dataset to retrieve from a local copy that Spice refreshes.

Explore SQL federation

Search and rank
results in one query

Run vector and full-text search next to SQL filters and joins. Reciprocal Rank Fusion merges the results, and you tune relevance per query.

Learn how hybrid search works

Understand, analyze,
and decide in SQL

SQL AI functions find the intent in each retrieved row and summarize results into insights. Decision functions such as ai_classify and ai_score return typed answers you can filter and act on.

Explore SQL AI functions

The full retrieval stack in one runtime

Hybrid search, ranking, model calls, and agent tools run in the same SQL engine. Large vector sets stay in object storage, and hot data stays local.

Hybrid search

Combine search with SQL

Call vector_search and text_search in standard SQL, next to your filters and joins. Results are tables, so you can filter, join, and aggregate them with the rest of your data.

Explore search features

Hybrid search combined with SQL: a query builds one clause at a time. Spice runs hybrid search on a tickets table and returns the results as a table, one row at a time. A WHERE clause keeps only billing tickets, and a JOIN on customers adds each customer plan to the rows that remainSELECT t.title, t.product, c.planFROM rrf(vector_search(...), text_search(...)) AS tJOIN customers c ON c.id = t.customer_idWHERE t.product = 'billing'titleproductplan1Cancel my subscriptionbillingPro2Pause my accountaccount3Fees to cancel my planbillingTeam4End my free trialtrialsSpice runs hybrid search and returns a table.A WHERE clause filters the results like any table.A JOIN adds customer data to each result.Search results and business data, in one query.
Ranking and re-ranking

Fuse and tune results with Reciprocal Rank Fusion

Weight each search and add a recency decay with Reciprocal Rank Fusion (RRF). Reorder the top results with a reranker or decision model, or sort them on decision functions such as ai_score and ai_probability.

Explore reranking docs

AI functions

Enrich search results with AI functions

Pass search results to a model with ai() functions in the same SQL query. Decision functions like ai_classify and ai_if return typed answers you can filter and route on.

Explore SQL AI functions

Tool calling

Let agents call search and SQL tools

Agents call the built-in search and sql tools over the Model Context Protocol (MCP), or through a model that Spice serves. Each tool call runs in the same runtime, over only the datasets in the Spicepod. The tools: search_registry setting exposes tool_search and tool_invoke, so the model finds and calls tools on demand. It requires an embedding model. With tools: auto, a model that has more than 20 tools uses the same registry when an embedding model is configured, and uses direct tools otherwise.

Explore the tool registry

Vector storage

Search billions of vectors in Amazon S3

Store, index, and retrieve embeddings with partitioned Amazon S3 Vectors indexes. Spice manages ingest, refresh, and metadata for each index, and embeds with hosted or local models.

See S3 Vectors docs

Acceleration

Serve hot data locally

Materialize hot data with Spice Cayenne acceleration, and keep large vector indexes in object storage. Index-only reads answer a query from the index, and filter pushdown reads only the rows that match. Common queries read less data, so they return faster.

Explore Spice Cayenne

Set up hybrid search in three steps

Hybrid search example
  1. Connect your documents

    In spicepod.yaml, add a dataset for the table that holds your text. Set acceleration.enabled: true to keep a local copy.

  2. Index a column for search

    Add embeddings for vector search and full_text_search for keyword search on the same column.

  3. Fuse both searches in SQL

    Start Spice with spice run. Call vector_search and text_search in one query, and merge the results with rrf().

  1. /plugin marketplace add spiceai/skills
  2. /plugin install spiceai@spiceai

Trusted by teams building intelligent applications

Run data-intensive workloads on a high-performance engine trusted by teams building real-time systems at scale.

Ramachandra Ramarathinam

“Spice is the data plane behind Summation. Every connector we ship, from Snowflake to a generic REST-as-a-table, collapses into one SQL surface, which is what makes our AI agents portable across a customer's stack.”

Ramachandra Ramarathinam

CTO, Summation

Tim Ottersburg

“Partnering with Spice AI has transformed how NRC Health delivers AI-driven insights. By unifying siloed data across systems, we accelerated AI feature development, reducing time-to-market from months to weeks - and sometimes days. With predictable costs and faster innovation, Spice isn't just solving some of our data and AI challenges - it's helping us redefine personalized healthcare.”

Tim Ottersburg

VP of Technology, NRC Health

Peter Janovsky

“Spice opened the door to take these critical control-plane datasets and move them next to our services in the runtime path.”

Peter Janovsky

Software Architect, Twilio

FAQs

Answers to common questions about building RAG pipelines and agentic retrieval with Spice

Agentic retrieval is retrieval that an AI agent directs: the agent decides when to search, what to query, and how to refine the query. In Spice, the agent calls built-in tools such as search, sql, list_datasets, and table_schema instead of a fixed retrieval step. Expose these tools to an external agent through the MCP server gateway at /v1/mcp, which requires runtime.auth. Or set tools: auto on a model in your Spicepod, so the model calls the tools during a chat completion.

RAG reduces hallucinations by grounding model responses in data retrieved at query time instead of relying only on training data. Models grounded in incomplete or outdated data are more likely to hallucinate, so retrieval quality and freshness matter as much as the model itself. Spice retrieves governed data from your sources with SQL and hybrid search, so the model can ground its answer in that data.

No. Spice creates embeddings with local or hosted models and runs vector similarity search inside the runtime. A vector database usually needs other systems for full-text search and for joins with structured data. Spice runs all of these in one runtime that you can deploy locally, in your cloud, or as a managed service.

Yes. Spice federates queries across databases, object stores, and APIs with standard SQL. One query can retrieve structured records and combine them with semantic search results. This grounds model responses in operational data without manual data engineering.

Use hosted models from providers such as OpenAI, Anthropic, and Amazon Bedrock, or run local models, through the Spice AI Gateway. Call a model in SQL with the ai() function, so retrieved rows go to the model in the same query. Decision functions such as ai_classify, ai_if, and ai_score label, filter, or score each search result. See LLM inference and AI model serving for how model serving works in Spice.

The rrf() SQL function merges the result sets with Reciprocal Rank Fusion. Each search can set a rank_weight, and time_column with recency_decay boosts recent rows. Give keyword search more weight for exact lookups, and vector search more weight for natural-language questions. To reorder the top results with a reranker, chat, or decision model, wrap the query in rerank(). A decision model returns the probability that each result is relevant. To sort on a typed judgment of your own, use ai_score or ai_probability in ORDER BY after a search narrows the candidates.

Spice runs as one process next to your application, in your cloud, or as a managed service on Spice Cloud. With default settings, Spice Cayenne acceleration answers retrieval from a local copy of hot data instead of each source. Amazon S3 Vectors stores millions or billions of embeddings without always-on compute. The search results cache is on by default, so a repeated search can return from the cache instead of running again.

Define your data, an embedding model, and a chat model in one spicepod.yaml file. Spice indexes the text columns you choose for vector and full-text search. Your application or agent then retrieves context with SQL and sends it to the model through the same runtime.

"Data sources" "Retrieval in SQL" ranked context "Spice runtime: federation, acceleration, embeddings, and search indexes" "Chat model through the AI Gateway" PostgreSQL Amazon S3 Databricks "vector_search()" "text_search()" "rrf()"
  1. Connect: add a dataset for each source. Turn on acceleration to keep a local copy for fast retrieval.
  2. Index: add embeddings and full_text_search to the text columns. Spice creates the vectors and a BM25 full-text index.
  3. Retrieve: call vector_search(), text_search(), and rrf() in SQL, or call the /v1/search HTTP API.
  4. Generate: pass the results to a chat model with the ai() SQL function, the OpenAI-compatible /v1/chat/completions API, or an agent.

The following Spicepod indexes the body column of a PostgreSQL tickets table for hybrid search:

version: v1
kind: Spicepod
name: support-rag

embeddings:
  - from: openai:text-embedding-3-small
    name: embed
    params:
      openai_api_key: ${secrets:OPENAI_API_KEY}

models:
  - from: openai:gpt-4o-mini
    name: assistant
    params:
      openai_api_key: ${secrets:OPENAI_API_KEY}
      tools: auto

datasets:
  - from: postgres:public.tickets
    name: tickets
    params:
      pg_host: ${secrets:PG_HOST}
      pg_db: support
      pg_user: ${secrets:PG_USER}
      pg_pass: ${secrets:PG_PASS}
    acceleration:
      enabled: true
    columns:
      - name: body
        embeddings:
          - from: embed
            row_id: id
        full_text_search:
          enabled: true
          row_id: id

Hybrid search combines vector similarity search and BM25 full-text search. Run each search as a table function, then merge the ranked lists with rrf(). Reciprocal Rank Fusion (RRF) scores each row by its rank in each list. Rows that rank high in both lists move to the top:

SELECT id, body, _fused_score
FROM rrf(
    vector_search(tickets, 'customer cannot reset password'),
    text_search(tickets, 'password reset', body),
    join_key => 'id'
)
ORDER BY _fused_score DESC
LIMIT 5;

Results are rows, so you can join and aggregate them like any other table. The /v1/search HTTP API runs vector search across one or more datasets.

Since Spice v2.4.3, the search functions accept SQL parameters such as $1. Pass the user's question and keywords as parameters instead of building the SQL string. For example, send this body to the /v1/sql HTTP API with Content-Type: application/json:

{
  "sql": "SELECT id, body, _fused_score FROM rrf(vector_search(tickets, $1), text_search(tickets, $2, body), join_key => 'id') ORDER BY _fused_score DESC LIMIT 5",
  "parameters": ["customer cannot reset password", "password reset"]
}

MethodSQL functionBest for
Vector searchvector_search()Natural-language questions and matches by meaning
Full-text search (BM25)text_search()Exact terms, product names, error codes, and IDs
Hybrid searchrrf()Questions that mix concepts and keywords
Re-rankingrerank()Higher precision in the top results before generation
Decision scoringai_score(), ai_probability()Sorting results on a typed judgment such as relevance or urgency
SQL over structured dataSELECT with joins and filtersFacts such as account status, order totals, and permissions

See Spice in action

Walk through your use case with an engineer and see how Spice handles federation, acceleration, and AI integration for production workloads.

Talk to an engineer (opens in a new tab)