Liking cljdoc? Tell your friends :D

vector-search.core


add!clj

(add! idx id v)
(add! idx id v metadata)
(add! idx id v metadata text)

Adds or replaces id with vector v. The index stores metadata outside hnswlib.

The five-argument form optionally indexes text for BM25 retrieval.

Adds or replaces id with vector v. The index stores metadata outside hnswlib.

The five-argument form optionally indexes text for BM25 retrieval.
sourceraw docstring

add-batch!clj

(add-batch! idx items)

Adds each {:id .. :vector .. :metadata .. :text ..} item and returns the count added.

Adds each {:id .. :vector .. :metadata .. :text ..} item and returns the count added.
sourceraw docstring

(bm25-search idx query k)
(bm25-search idx query k opts)

Returns BM25 text matches best-first in the standard result-map shape.

The index lowercases the text and splits it on non-alphanumeric characters. Options :k1 and :b default to 1.2 and 0.75.

Returns BM25 text matches best-first in the standard result-map shape.

The index lowercases the text and splits it on non-alphanumeric characters.
Options `:k1` and `:b` default to 1.2 and 0.75.
sourceraw docstring

get-itemclj

(get-item idx id)

Returns {:id .. :vector float[] .. :metadata ..} for id, or nil.

Returns {:id .. :vector float[] .. :metadata ..} for id, or nil.
sourceraw docstring

(hybrid-search idx query-vec query-text k)
(hybrid-search idx query-vec query-text k opts)

Fuses dense vector and BM25 text retrieval into standard result maps.

The default :fusion is reciprocal rank fusion (:rrf) with :rrf-k 60. :fusion :weighted min-max normalizes each score list and combines it with :dense-weight and :sparse-weight. Each weight defaults to 0.5.

Fuses dense vector and BM25 text retrieval into standard result maps.

The default `:fusion` is reciprocal rank fusion (`:rrf`) with `:rrf-k` 60.
`:fusion :weighted` min-max normalizes each score list and combines it with
`:dense-weight` and `:sparse-weight`. Each weight defaults to 0.5.
sourceraw docstring

indexclj

(index opts)

Creates an embedded vector index handle.

:type is :hnsw by default. :exact does an exhaustive exact search, O(n) per query, with no tuning knobs. Use it as ground truth, or for a small corpus. :ef trades recall for speed during search; higher values improve recall.

Creates an embedded vector index handle.

:type is :hnsw by default. :exact does an exhaustive exact search, O(n) per
query, with no tuning knobs. Use it as ground truth, or for a small corpus.
:ef trades recall for speed during search; higher values improve recall.
sourceraw docstring

load-indexclj

(load-index path)

Loads an index handle from path, a directory containing index.bin and meta.edn.

:type in meta.edn selects :hnsw or :exact. An older save without :type loads as :hnsw. :exact does an exhaustive exact search, O(n) per query, with no tuning knobs. Use it as ground truth, or for a small corpus.

Loads an index handle from path, a directory containing index.bin and meta.edn.

:type in meta.edn selects :hnsw or :exact. An older save without :type loads
as :hnsw. :exact does an exhaustive exact search, O(n) per query, with no
tuning knobs. Use it as ground truth, or for a small corpus.
sourceraw docstring

remove!clj

(remove! idx id)

Removes id from the index. Returns true when an item was removed.

Removes id from the index. Returns true when an item was removed.
sourceraw docstring

saveclj

(save idx path)

Saves idx into path, a directory. Creates the directory when absent. Returns path.

Saves idx into path, a directory. Creates the directory when absent. Returns path.
sourceraw docstring

(search idx query-vec k)
(search idx query-vec k {:keys [filter] :as opts})

Returns nearest results best-first.

For :cosine and :dot, :score is a similarity where higher is better. For :euclidean, :score is L2 distance where lower is better.

With opts, :filter can be a structured metadata filter (:eq, :in, :range, :gt, :lt, :and, :or, or :not) or a predicate over the result map. Structured equality and membership use an inverted metadata index. The index then scores only the matching vectors. Predicate filtering keeps the original candidate over-fetch behavior.

Returns nearest results best-first.

For :cosine and :dot, :score is a similarity where higher is better. For
:euclidean, :score is L2 distance where lower is better.

With opts, `:filter` can be a structured metadata filter (`:eq`, `:in`,
`:range`, `:gt`, `:lt`, `:and`, `:or`, or `:not`) or a predicate over the
result map. Structured equality and membership use an inverted metadata
index. The index then scores only the matching vectors. Predicate filtering
keeps the original candidate over-fetch behavior.
sourceraw docstring

sizeclj

(size idx)

Returns the number of indexed items.

Returns the number of indexed items.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close