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=http://luarocks.org/dev annoy
    License: Apache 2.0
    Lua compatibility: Lua >= 5.1, LuaJIT >= 2.0
    Homepage: https://github.com/spotify/annoy

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)
    end

    t:build(10) -- 10 trees
    t:save('test.ann')

    -- ...

    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)
    end


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


[1] https://github.com/spotify/annoy
[2] https://github.com/spotify/annoy/blob/master/README_Lua.md
[3] https://github.com/spotify/annoy#full-python-api


-- 


Best regards,
Boris Nagaev