Filtered Search with VBase¶
This example combines relational filters and vector search in one PostgreSQL query.
DROP TABLE IF EXISTS akasicdb_example_tenant_articles;
CREATE TABLE akasicdb_example_tenant_articles (
id integer PRIMARY KEY,
tenant_id integer NOT NULL,
category_id integer NOT NULL,
status text NOT NULL,
title text NOT NULL,
created_at timestamptz NOT NULL,
embedding vector(3) NOT NULL
);
INSERT INTO akasicdb_example_tenant_articles
(id, tenant_id, category_id, status, title, created_at, embedding)
VALUES
(101, 1, 10, 'published', 'close article from another tenant', '2026-05-01', ARRAY[0.10, 0.10, 0.00]::real[]::vector),
(102, 2, 10, 'draft', 'close draft article', '2026-05-02', ARRAY[0.11, 0.10, 0.00]::real[]::vector),
(201, 2, 10, 'published', 'tenant guide overview', '2026-05-03', ARRAY[0.12, 0.10, 0.00]::real[]::vector),
(202, 2, 10, 'published', 'tenant guide indexing', '2026-05-04', ARRAY[0.20, 0.10, 0.00]::real[]::vector),
(203, 2, 10, 'published', 'tenant guide operations', '2026-05-05', ARRAY[0.28, 0.10, 0.00]::real[]::vector),
(204, 2, 20, 'published', 'different category', '2026-05-06', ARRAY[0.13, 0.10, 0.00]::real[]::vector),
(205, 2, 10, 'archived', 'archived close article', '2026-05-07', ARRAY[0.14, 0.10, 0.00]::real[]::vector),
(301, 3, 10, 'published', 'close article from tenant three', '2026-05-08', ARRAY[0.15, 0.10, 0.00]::real[]::vector);
CREATE INDEX akasicdb_tenant_articles_meta_idx
ON akasicdb_example_tenant_articles (tenant_id, category_id, status, created_at);
CREATE INDEX akasicdb_tenant_articles_embedding_idx
ON akasicdb_example_tenant_articles
USING vectoron (embedding vector_l2_ops)
WITH (options = $$
[indexing.hnsw]
$$);
SELECT fence_vector_index('akasicdb_tenant_articles_embedding_idx'::regclass);
BEGIN;
SET LOCAL vectoron.search_mode = 'vbase';
SELECT id, title
FROM akasicdb_example_tenant_articles
WHERE tenant_id = 2
AND category_id = 10
AND status = 'published'
AND created_at >= TIMESTAMPTZ '2026-05-01'
ORDER BY embedding <-> ARRAY[0.10, 0.10, 0.00]::real[]::vector
LIMIT 3;
COMMIT;
Query Shape¶
| Part | Role |
|---|---|
| B-tree index | Supports scalar predicates such as tenant_id, category_id, status, and created_at |
| AkasicDB vector index | Supports vector ordering with ORDER BY embedding <-> ... |
vectoron.search_mode = 'vbase' |
Applies VBase search mode for the transaction |
The query result contains rows that satisfy the scalar predicates. The matching rows are ordered by vector distance inside the same SQL statement.