lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hello, everyone!

I'm very happy to announce that Annoy (approximate nearest neighbors
[1]) now supports Lua [2].

Annoy (Approximate Nearest Neighbors Oh Yeah) is a C++ library with
Python Go and Lua bindings to search for points in space that are
close to a given query point. It also creates large read-only
file-based data structures that are mmapped into memory so that many
processes may share the same data.

    Install: luarocks install --server= annoy
    License: Apache 2.0
    Lua compatibility: Lua >= 5.1, LuaJIT >= 2.0

Lua code example:

    local annoy = require "annoy"

    local f = 3  -- Length of item vector that will be indexed
    local t = annoy.AnnoyIndex(f)
    for i = 0, 999 do
      local v = {math.random(), math.random(), math.random()}
      t:add_item(i, v)

    t:build(10) -- 10 trees

    -- ...

    local u = annoy.AnnoyIndex(f)
    u:load('test.ann') -- super fast, will just mmap the file

    -- find the 10 nearest neighbors
    local neighbors = u:get_nns_by_item(0, 10)
    for rank, i in ipairs(neighbors) do
      print("neighbor", rank, "is", i)

Lua API closely resembles Python API of Annoy [3].



Best regards,
Boris Nagaev