discourse-ai/lib/embeddings/vector_representations
Rafael dos Santos Silva 791fad1e6a
FEATURE: Index embeddings using bit vectors (#824)
On very large sites, the rare cache misses for Related Topics can take around 200ms, which affects our p99 metric on the topic page. In order to mitigate this impact, we now have several tools at our disposal.

First, one is to migrate the index embedding type from halfvec to bit and change the related topic query to leverage the new bit index by changing the search algorithm from inner product to Hamming distance. This will reduce our index sizes by 90%, severely reducing the impact of embeddings on our storage. By making the related query a bit smarter, we can have zero impact on recall by using the index to over-capture N*2 results, then re-ordering those N*2 using the full halfvec vectors and taking the top N. The expected impact is to go from 200ms to <20ms for cache misses and from a 2.5GB index to a 250MB index on a large site.

Another tool is migrating our index type from IVFFLAT to HNSW, which can increase the cache misses performance even further, eventually putting us in the under 5ms territory. 

Co-authored-by: Roman Rizzi <roman@discourse.org>
2024-10-14 13:26:03 -03:00
..
all_mpnet_base_v2.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
base.rb FEATURE: Index embeddings using bit vectors (#824) 2024-10-14 13:26:03 -03:00
bge_large_en.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
bge_m3.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
gemini.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
multilingual_e5_large.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
text_embedding_3_large.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
text_embedding_3_small.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00
text_embedding_ada_002.rb DEV: Move to single table per embeddings type (#561) 2024-08-08 11:55:20 -03:00