Skip to content

Vector Search Basics

This example shows exact vector ordering before any AkasicDB vector index exists on the table. It uses one query vector with squared L2 distance, negative dot product, and cosine distance.

DROP TABLE IF EXISTS akasicdb_example_articles_minimal;

CREATE TABLE akasicdb_example_articles_minimal (
  id integer PRIMARY KEY,
  title text NOT NULL,
  embedding vector(3) NOT NULL
);

INSERT INTO akasicdb_example_articles_minimal (id, title, embedding) VALUES
  (1, 'vector indexes overview', ARRAY[1.0, 0.0, 0.0]::real[]::vector),
  (2, 'nearest neighbor search', ARRAY[0.9, 0.1, 0.0]::real[]::vector),
  (3, 'query tuning notes', ARRAY[0.7, 0.2, 0.0]::real[]::vector),
  (4, 'graph traversal basics', ARRAY[0.0, 1.0, 0.0]::real[]::vector),
  (5, 'storage operations', ARRAY[0.0, 0.0, 1.0]::real[]::vector),
  (6, 'release checklist', ARRAY[-1.0, 0.0, 0.0]::real[]::vector),
  (7, 'hybrid application notes', ARRAY[0.4, 0.4, 0.4]::real[]::vector);

SELECT id, title, embedding <-> ARRAY[1.0, 0.0, 0.0]::real[]::vector AS l2_distance
FROM akasicdb_example_articles_minimal
ORDER BY embedding <-> ARRAY[1.0, 0.0, 0.0]::real[]::vector
LIMIT 3;

SELECT id, title, embedding <#> ARRAY[1.0, 0.0, 0.0]::real[]::vector AS negative_dot
FROM akasicdb_example_articles_minimal
ORDER BY embedding <#> ARRAY[1.0, 0.0, 0.0]::real[]::vector
LIMIT 3;

SELECT id, title, embedding <=> ARRAY[1.0, 0.0, 0.0]::real[]::vector AS cosine_distance
FROM akasicdb_example_articles_minimal
ORDER BY embedding <=> ARRAY[1.0, 0.0, 0.0]::real[]::vector
LIMIT 3;

SELECT count(*) AS vector_index_count
FROM vectoron_index_stat
WHERE tablename = 'akasicdb_example_articles_minimal';

Operators

Operator Ordering meaning Notes
<-> Squared L2 distance Smaller distance ranks first
<#> Negative dot product More similar vectors rank first because the stored value is negative dot product
<=> Cosine distance Smaller distance ranks first

The final query checks vectoron_index_stat. A count of 0 means the table has no AkasicDB vector index, so the preceding searches use exact SQL ordering.