Vector Search over Parquet Files with SQL
SereneDB runs nearest-neighbor and hybrid search over embeddings stored in Parquet files without loading the rows into a table. You expose the files through a view over read_parquet, index the view with an inverted index that holds a vector column, and order by the distance to a query vector. Every query runs from psql or any Postgres driver.
Tested with SereneDB 26.11.2 on 2026-11-20.
The examples read and write files under /data, the folder mounted into the server's container in How to Read a Parquet File with SQL.
Expose the embeddings through a view
A Parquet file of embeddings usually has an id, the text and the embedding as a list of floats. This sample file has five support tickets with three-dimensional embeddings written by hand, so the distances stay easy to follow: the first axis means roughly "search", the second "performance", the third "billing". Real embeddings come from a model and have hundreds of dimensions.
COPY ( SELECT * FROM (VALUES (1, 'Search results are empty after the index rebuild', [0.9, 0.1, 0.0]::FLOAT[]), (2, 'Invoice PDF shows the wrong company address', [0.0, 0.0, 1.0]::FLOAT[]), (3, 'Slow search when the query has many words', [0.7, 0.7, 0.0]::FLOAT[]), (4, 'Export endpoint times out on large result sets', [0.1, 0.95, 0.0]::FLOAT[]), (5, 'Typo on the search settings page', [0.6, 0.0, 0.1]::FLOAT[]) ) AS t(id, body, emb)) TO '/data/tickets.parquet' (FORMAT parquet);Parquet stores the embedding as a variable-length list, so SereneDB reads it as FLOAT[]:
DESCRIBE SELECT * FROM '/data/tickets.parquet';column_name | column_type | null | key | default | extra -------------+-------------+------+------+---------+------- id | INTEGER | YES | NULL | NULL | NULL body | VARCHAR | YES | NULL | NULL | NULL emb | FLOAT[] | YES | NULL | NULL | NULL
A vector index needs a fixed-size FLOAT[N] column (Column types). Cast the column in the view, with N set to the model's dimension:
CREATE VIEW tickets AS SELECT id, body, emb::FLOAT[3] AS emb FROM read_parquet('/data/tickets.parquet');Build a vector index over the view
SereneDB indexes the view like a table. This index holds the text for BM25 with a stemming dictionary, and the embedding in an ivf vector index with the cosine metric. The rows stay in the Parquet file.
CREATE TEXT SEARCH DICTIONARY english_dict AS split_text(case := 'lower') | normalize_tokens('en_US.UTF-8', accent := false) | stem_words('en_US.UTF-8') WITH (frequency, position, offset);CREATE INDEX tickets_idx ON tickets USING inverted (id, body english_dict, emb ivf (metric = 'cosine'));The metric decides which distance operator the index serves:
| Metric | Operator | Distance |
|---|---|---|
cosine | <=> | cosine distance |
l2 | <-> | Euclidean distance |
ip | <#> | negative inner product |
l1 | <+> | Manhattan distance |
Use the metric your embedding model was trained for; most text embedding models are compared with cosine. Vector Search covers quantization and the nprobe setting that trades recall for speed.
hnsw builds a graph index instead of ivf clusters, with the same metrics and operators:
CREATE INDEX tickets_hnsw ON tickets USING inverted (id, emb hnsw (metric = 'cosine'));Find the nearest neighbors
A kNN query orders by the distance to the query vector and takes the first k rows. Query the index by its name. The query vector here means "slow and search-related":
SELECT id, body, round((emb <=> [0.5, 0.85, 0.0]::FLOAT[3])::numeric, 3) AS distanceFROM tickets_idxORDER BY distance, idLIMIT 3;id | body | distance ----+--------------------------------------------------+---------- 3 | Slow search when the query has many words | 0.032 4 | Export endpoint times out on large result sets | 0.090 1 | Search results are empty after the index rebuild | 0.401
Ticket 4 ranks second although it shares no word with "slow search": its embedding sits close to the query on the "performance" axis.
Turn a question into a query vector
SereneDB can compute embeddings in SQL with ai_embed, which calls an embedding model through an OpenAI-compatible endpoint. These examples use a local Ollama server with the all-minilm model (384 dimensions); Providers covers hosted providers and other endpoints.
CREATE SECRET local_ai ( TYPE openai, base_url 'http://localhost:11434', embeddings_path '/v1/embeddings');base_url must be an address the server can reach. When SereneDB runs in Docker, localhost is the container itself, so point it at the Ollama host instead and allow the plain-HTTP endpoint with SET sdb_ai_allow_insecure_endpoint = true (Providers).
Embed the text of the tickets once, write the result as Parquet, and index it through a view that casts to FLOAT[384]:
COPY ( SELECT id, body, ai_embed(body, 'all-minilm', 'local_ai') AS emb FROM read_parquet('/data/tickets.parquet')) TO '/data/tickets_minilm.parquet' (FORMAT parquet);
CREATE VIEW tickets_minilm AS SELECT id, body, emb::FLOAT[384] AS emb FROM read_parquet('/data/tickets_minilm.parquet');
CREATE INDEX tickets_minilm_idx ON tickets_minilm USING inverted (id, emb ivf (metric = 'cosine'));At query time, embed the question in the same ORDER BY:
SELECT id, bodyFROM tickets_minilm_idxORDER BY emb <=> ai_embed('billing problem', 'all-minilm', 'local_ai')::FLOAT[384]LIMIT 2;id | body ----+--------------------------------------------- 2 | Invoice PDF shows the wrong company address 5 | Typo on the search settings page
The query vector must come from the same model as the stored embeddings. If your application already computes embeddings, send the vector from any Postgres driver instead of calling ai_embed.
Combine BM25 and vector search
Hybrid search uses both signals: BM25 matches the words of the query, and the vector distance matches its meaning. SereneDB keeps both in one index, so one query can use them together.
Filter by keyword, rank by meaning
A keyword match in WHERE keeps only tickets about search; the vector orders them by how close they are to "slow":
SELECT id, bodyFROM tickets_idxWHERE body @@ 'search'ORDER BY emb <=> [0.5, 0.85, 0.0]::FLOAT[3], idLIMIT 3;id | body ----+-------------------------------------------------- 3 | Slow search when the query has many words 1 | Search results are empty after the index rebuild 5 | Typo on the search settings page
Fuse the two rankings
BM25 alone returns only the tickets that contain the words:
SELECT id, bodyFROM tickets_idxWHERE body @@ 'slow search'ORDER BY BM25(tickets_idx.tableoid) DESC, id;id | body ----+-------------------------------------------------- 3 | Slow search when the query has many words 1 | Search results are empty after the index rebuild 5 | Typo on the search settings page
Reciprocal rank fusion merges the BM25 ranking and the vector ranking into one list. BM25 scores are better when higher and distances when lower, so the BM25 branch ranks descending and the vector branch ascending:
WITH fused AS ( SELECT id, RANK() OVER (ORDER BY s DESC) AS rank FROM ( SELECT id, BM25(tickets_idx.tableoid) AS s FROM tickets_idx WHERE body @@ 'slow search' ORDER BY s DESC LIMIT 100 ) t UNION ALL SELECT id, RANK() OVER (ORDER BY d) AS rank FROM ( SELECT id, emb <=> [0.5, 0.85, 0.0]::FLOAT[3] AS d FROM tickets_idx ORDER BY d LIMIT 100 ) t)SELECT f.id, t.body, round(SUM(1.0 / (60 + f.rank)), 4) AS rrf_scoreFROM fused f JOIN tickets t USING (id)GROUP BY f.id, t.bodyORDER BY rrf_score DESC, f.id;id | body | rrf_score ----+--------------------------------------------------+----------- 3 | Slow search when the query has many words | 0.0328 1 | Search results are empty after the index rebuild | 0.032 5 | Typo on the search settings page | 0.0318 4 | Export endpoint times out on large result sets | 0.0161 2 | Invoice PDF shows the wrong company address | 0.0154
Ticket 4 now appears in the results: the vector branch brings it in, although it contains none of the query words. Hybrid Search shows more ways to weigh the two signals.
Folders of files and S3
A view can read a glob of Parquet files, on local disk or in S3, and the index covers all of them. With an S3 secret for the bucket:
CREATE VIEW all_tickets AS SELECT id, body, emb::FLOAT[3] AS emb FROM read_parquet('s3://⟨my-bucket⟩/tickets/*.parquet');
CREATE INDEX all_tickets_idx ON all_tickets USING inverted (id, body english_dict, emb ivf (metric = 'cosine'));The index holds a snapshot of the files. When files are added, changed or removed behind the glob, refresh it in one pass; behind a glob, REINDEX INDEX re-reads only the files that changed (Refreshing the index):
REINDEX INDEX all_tickets_idx;
SELECT idFROM all_tickets_idxORDER BY emb <=> [0.0, 0.0, 1.0]::FLOAT[3]LIMIT 1;id ---- 2
FAQ
Do I need a vector database to search embeddings in Parquet files?
No. SereneDB builds a vector index over a view of the Parquet files and answers kNN queries in SQL, while the rows stay in the files. The same index can also serve BM25 full-text search over the text columns.
How should I store embeddings in Parquet?
Store each embedding as a list of 32-bit floats in one column, next to an id and the text it was computed from. SereneDB reads that column as FLOAT[]; cast it to FLOAT[N] in the view, with N equal to the model's dimension.
Which distance metric should I use?
Use the metric the embedding model was built for. Most text embedding models, including all-minilm, compare vectors with cosine similarity, so metric = 'cosine' with the <=> operator is the usual choice.
What is the difference between hybrid search and vector search?
Vector search ranks rows by how close their embeddings are to the query's embedding, which captures meaning. Hybrid search combines that with keyword search such as BM25, which captures exact words, names and codes. In SereneDB both run over the same index, and reciprocal rank fusion merges the two rankings.
Does SereneDB copy my Parquet data?
The rows stay in the Parquet files, and SereneDB reads them through the view. The index stores the search postings and the vector column it indexes, so queries can rank rows without rescanning every file.