콘텐츠로 이동

Filtered Search with VBase

이 예제에서는 한 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

구성 역할
B-tree index tenant_id, category_id, status, created_at predicate 지원
AkasicDB vector index ORDER BY embedding <-> ... vector ordering 지원
vectoron.search_mode = 'vbase' transaction 범위에 VBase search mode 적용

Query는 scalar predicate를 만족하는 row만 결과에 포함하고, 같은 SQL statement에서 vector distance 기준의 ordering을 계산합니다.