A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://unum-cloud.github.io/usearch/java below:

Java SDK - Unum ยท USearch 2.19.3 documentation

Back to top

Toggle table of contents sidebar

Java SDK# USearch for Java# Installation#
<dependency>
  <groupId>cloud.unum</groupId>
  <artifactId>usearch</artifactId>
  <version>2.19.3</version>
</dependency>

Add that snippet to your pom.xml and hit mvn install.

Quickstart#
import cloud.unum.usearch.Index;

public class Main {
    public static void main(String[] args) {
        try (Index index = new Index.Config()
                .metric("cos")
                .quantization("f32")
                .dimensions(3)
                .capacity(100)
                .build()) {

            // Add to Index
            float[] vector = {0.1f, 0.2f, 0.3f};
            index.add(42, vector);

            // Search
            int[] keys = index.search(new float[]{0.1f, 0.2f, 0.3f}, 10);
            for (int key : keys) {
                System.out.println("Found key: " + key);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Serialization#

To save and load the index from disk, use the following methods:

index.save("index.usearch");
index.load("index.usearch");
index.view("index.usearch");
Extracting, Updating, and Removing Values#

It is generally not recommended to use HNSW indexes in case of frequent removals or major distribution shifts. For small updates, you can use the following methods:

float[] vector = index.get(42);
boolean removed = index.remove(42);
boolean renamed = index.rename(43, 42);

To obtain metadata:

long size = index.size();
long capacity = index.capacity();
long dimensions = index.dimensions();
long connectivity = index.connectivity();

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4