Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Locality Sensitive Hashing at Lyst
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Maciej Kula
July 24, 2015
Programming
1.4k
0
Share
Locality Sensitive Hashing at Lyst
Description of the intuition behind locality sensitive hashing and its application at Lyst.
Maciej Kula
July 24, 2015
More Decks by Maciej Kula
See All by Maciej Kula
Implicit and Explicit Recommender Systems
maciejkula
0
3k
Binary Embeddings For Efficient Ranking
maciejkula
0
720
Rust for Python Native Extensions
maciejkula
0
490
Hybrid Recommender Systems at PyData Amsterdam 2016
maciejkula
5
2.9k
Recommendations under sparsity
maciejkula
1
390
Metadata Embeddings for User and Item Cold-start Recommendations
maciejkula
2
1k
Other Decks in Programming
See All in Programming
ふつうのFeature Flag実践入門
irof
7
3.3k
関係性から理解する"同一性"の型用語たち
pvcresin
2
610
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
1.2k
inferと仲良くなる10分間
ryokatsuse
1
270
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
970
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
220
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
140
net-httpのHTTP/2対応について
naruse
0
350
横断組織出身のQAEがインプロセスQAEでつまずいたこと・活かせたこと
ty89
0
460
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
180
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.3k
iOS26時代の新規アプリ開発
yuukiw00w
0
210
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
Abbi's Birthday
coloredviolet
2
7.8k
My Coaching Mixtape
mlcsv
0
140
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
190
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.5k
How STYLIGHT went responsive
nonsquared
100
6.1k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
190
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
Transcript
Speeding up search with locality sensitive hashing. by Maciej Kula
Hi, I’m Maciej Kula. @maciej_kula
We collect the world of fashion into a customisable shopping
experience.
Given a point, find other points close to it. Nearest
neighbour search… 4
None
At Lyst we use it for… 1.) Image Search 2.)
Recommendations 6
Convert image to points in space (vectors) & use nearest
neighbour search to get similar images. 1. Image Search (-0.3, 2.1, 0.5)
Super useful for deduplication & search.
Convert products and users to points in space & use
nearest neighbour search to get related products for the user. 2. Recommendations user = (-0.3, 2.1, 0.5) product = (5.2, 0.3, -0.5)
Great, but…
11 80 million We have images
12 9 million We have products
Exhaustive nearest neighbour search is too slow.
Locality sensitive hashing to the rescue! Use a hash table.
Pick a hash function that puts similar points in the same bucket. Only search within the bucket.
We use Random Projection Forests
Partition by splitting on random vectors
Partition by splitting on random vectors
Partition by splitting on random vectors
Partition by splitting on random vectors
Partition by splitting on random vectors
Points to note Keep splitting until the nodes are small
enough. Median splits give nicely balanced trees. Build a forest of trees.
Why do we need a forest? Some partitions split the
true neighbourhood of a point. Because partitions are random, other trees will not repeat the error. Build more trees to trade off query speed for precision.
LSH in Python annoy, Python wrapper for C++ code. LSHForest,
part of scikit-learn FLANN, an auto-tuning ANN index
But… LSHForest is slow. FLANN is a pain to deploy.
annoy is great, but can’t add points to an existing index.
So we wrote our own.
github.com/lyst/rpforest pip install rpforest
rpforest Quite fast. Allows adding new items to the index.
Does not require us to store points in memory.
We use it in conjunction with PostgreSQL Send the query
point to the ANN index. Get ANN row ids back Plug them into postgres for filtering Final scoring done in postgres using C extensions.
Side note: postgres is awesome. Arrays & custom functions in
C
Gives us a fast and reliable ANN service 100x speed-up
with 0.6 10-NN precision Allows us to serve real-time results All on top of a real database.
thank you @maciej_kula