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
Maciej Kula
July 24, 2015
Programming
0
1.3k
Locality Sensitive Hashing at Lyst
Description of the intuition behind locality sensitive hashing and its application at Lyst.
Maciej Kula
July 24, 2015
Tweet
Share
More Decks by Maciej Kula
See All by Maciej Kula
Implicit and Explicit Recommender Systems
maciejkula
0
2.9k
Binary Embeddings For Efficient Ranking
maciejkula
0
680
Rust for Python Native Extensions
maciejkula
0
470
Hybrid Recommender Systems at PyData Amsterdam 2016
maciejkula
5
2.7k
Recommendations under sparsity
maciejkula
1
360
Metadata Embeddings for User and Item Cold-start Recommendations
maciejkula
2
960
Other Decks in Programming
See All in Programming
AI Agents: How Do They Work and How to Build Them @ Shift 2025
slobodan
0
110
Design Foundational Data Engineering Observability
sucitw
3
210
為你自己學 Python - 冷知識篇
eddie
1
350
複雑なフォームに立ち向かう Next.js の技術選定
macchiitaka
2
240
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
420
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
3
260
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
780
Reading Rails 1.0 Source Code
okuramasafumi
0
250
概念モデル→論理モデルで気をつけていること
sunnyone
3
300
API Platform 4.2: Redefining API Development
soyuka
0
220
アプリの "かわいい" を支えるアニメーションツールRiveについて
uetyo
0
280
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
250
Featured
See All Featured
A better future with KSS
kneath
239
17k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
Building Applications with DynamoDB
mza
96
6.6k
A Tale of Four Properties
chriscoyier
160
23k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Fireside Chat
paigeccino
39
3.6k
GraphQLの誤解/rethinking-graphql
sonatard
72
11k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Navigating Team Friction
lara
189
15k
Scaling GitHub
holman
463
140k
Done Done
chrislema
185
16k
Git: the NoSQL Database
bkeepers
PRO
431
66k
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