Skip to content

Zig lib#710

Open
pacifio wants to merge 2 commits intounum-cloud:mainfrom
pacifio:zig-lib
Open

Zig lib#710
pacifio wants to merge 2 commits intounum-cloud:mainfrom
pacifio:zig-lib

Conversation

@pacifio
Copy link

@pacifio pacifio commented Feb 14, 2026

This PR adds zig API that can be easily installed via zig fetch and can be used as a high level binding

Configure your build.zig
Add the dependency to your executable or library:

const usearch_dep = b.dependency("usearch_zig", .{
    .target = target,
    .optimize = optimize,
});

exe.root_module.addImport("usearch_zig", usearch_dep.module("usearch_zig"));

exe.root_module.link_libc = true;
exe.root_module.link_libcpp = true;

Quick Start

const std = @import("std");
const usearch = @import("usearch_zig");

pub fn main() !void {
    const allocator = std.heap.page_allocator;

    // Create an index for 3-dimensional vectors
    const config = usearch.IndexConfig.default(3);
    var index = try usearch.Index.init(allocator, config);
    defer index.deinit();

    // Add some vectors
    var vec1 = [_]f32{ 1.0, 2.0, 3.0 };
    var vec2 = [_]f32{ 4.0, 5.0, 6.0 };

    try index.add(1, &vec1);
    try index.add(2, &vec2);

    // Search for similar vectors
    const results = try index.search(&vec1, 2);
    defer allocator.free(results);

    for (results) |result| {
        std.debug.print("Key: {}, Distance: {}\n", .{
            result.key,
            result.distance,
        });
    }
}

@ashvardanian ashvardanian added the v3 Breaking changes planned for v3 label Feb 16, 2026
@ashvardanian
Copy link
Contributor

Hi @pacifio! Thanks for the PR! I believe this might be the 14th language binding for USearch at this point. I'll consider including it into the v3, in case it won't stretch the surface area too much 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 Breaking changes planned for v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants