Skip to content

Indexing

Define AkasicDB vector indexes with PostgreSQL CREATE INDEX ... USING vectoron. The SQL on this page runs in a database where AkasicDB vector features are available.

Create the shared example table.

CREATE TABLE items (
  id bigserial PRIMARY KEY,
  category_id integer NOT NULL,
  embedding vector(3) NOT NULL
);

INSERT INTO items (category_id, embedding)
SELECT (i % 10), ARRAY[random(), random(), random()]::real[]
FROM generate_series(1, 100000) AS i;

Warning

Vector index count and per-index vector limits depend on the edition and build. Check the limits applied to your edition with the SQL functions covered in Operations.

Create a Vamana Index

Vamana is an ANN index for L2-distance workloads. See Vamana for detailed options and query-time tuning.

Note

Vamana examples use vector_l2_ops and <->.

CREATE INDEX items_embedding_vamana_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.vamana]
    alpha = 1.2
    r = 32
    l_search = 64
    phase = 1
  $$);

Segment and Optimization Options

These options tune segment handling and background optimization independently of the index type.

CREATE INDEX items_embedding_vamana_tuned_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.vamana]
    alpha = 1.2
    r = 32
    l_search = 64
    phase = 1

    [segment]
    max_growing_segment_size = 200000
    max_sealed_segment_size = 1000000

    [optimizing]
    delete_threshold = 0.1
    optimizing_secs = 1000
    optimizing_threads = 8
    sealing_secs = 60
    sealing_size = 5000
  $$);
Option Default Notes
segment.max_growing_segment_size 1000000 Maximum number of vectors in a growing segment before it moves to a sealed segment.
segment.max_sealed_segment_size 4000000000 Maximum number of vectors in a sealed segment.
optimizing.delete_threshold 0.2 Deleted-vector ratio that can make a segment eligible for merge or optimization.
optimizing.optimizing_secs 600 Minimum wait between optimization attempts.
optimizing.optimizing_threads 4 Worker count for background merge and optimization. Higher values may increase parallel background work and CPU use.
optimizing.sealing_secs 60 Delay before sealing a segment after the threshold is reached.
optimizing.sealing_size 5000 Vector-count threshold for moving the write buffer into a growing segment.

Other Indexes

Other Vector Indexes covers HNSW, IVF, Flat, and Sparse Inverted Index syntax and options.