ankane / faiss-ruby

Efficient similarity search and clustering for Ruby
MIT License
124 stars 4 forks source link

Possible support for add_with_ids? #3

Closed clarkware closed 1 year ago

clarkware commented 1 year ago

I'm new to Faiss so this request might be misguided, but I'm curious if you have plans to support an index that has an add_with_ids method as described here.

The use case would be to assign ids to table records so you could fetch associated records using the ids returned by the search method. For example, I'd like to store text content and the embedding (vector representation) of that content. Unless I'm overlooking something, I'd need to store the original content outside of Faiss in a relational database or such and store the embedding vectors in Faiss. After performing a Faiss search, I then need to fetch the content associated with the matching embeddings. And while it's possible to use the auto-generated Faiss ids, it would be really convenient to be able to provide ids in addition to the vectors when calling the add method.

If it helps, the ex_faiss Elixir bindings have an add_with_ids function.

Anyway, just wondering if that's something that could be supported without a lot of effort. :-)

Thanks!

ankane commented 1 year ago

Hey @clarkware, thanks for the suggestion. Added both the IndexIDMap class and add_with_ids method in the commits above.

clarkware commented 1 year ago

Excellent, thanks!