# From Pre-trained to Fine-tuned: Nextdoor’s Path to Effective Embedding Applications

[Nextdoor](https://yomu.fyi/company/nextdoor) · Karthik Jayasurya · Sep 7, 2023

**Type:** Problem & solution

## Summary

Nextdoor transitioned its ranking and recommendation pipelines from traditional continuous and discrete interaction features to transformer-based representation learning. The engineering team deployed pre-trained Sentence-BERT models to generate multilingual post and comment representations, which were aggregated daily by interaction type to form user embeddings. To improve search recall, the team fine-tuned sentence transformers on unlabeled query session logs using contrastive learning and integrated HNSWlib for approximate nearest neighbor retrieval. Subsequent iterations incorporated labeled feedback, BERTopic for coarse personalization, and experiments with CLIP image embeddings. Infrastructure scaling challenges were addressed by performing embedding transformations directly within FeatureStore and optimizing feature payload formats to minimize microservice network bandwidth.

## Context

Nextdoor relied primarily on continuous and discrete features from interaction logs for ML ranking systems like feed ranking and notifications scoring. These models lacked deep content understanding from text and images, requiring transformer-based representation learning to capture nuanced user signals and improve personalization and local search.

## Approach / What changed

Nextdoor implemented entity embedding models across three phases: using pre-trained Sentence-BERT for multilingual text representations and weighted user aggregations, fine-tuning search query embeddings using self-supervised contrastive learning and HNSWlib, and applying labeled fine-tuning along with BERTopic and CLIP. Transformations were moved directly into FeatureStore to lower serving costs.

## Takeaways

- Pre-trained multilingual Sentence-BERT models generated post and comment embeddings that were aggregated daily by interaction weight into user embeddings, boosting notification and feed ranking metrics.
- Self-supervised contrastive learning on search query logs paired with HSNWlib approximate nearest neighbor search improved search recall, reduced null queries, and sped up query expansion latencies by more than 10x.
- Transforming high-dimensional embedding vectors directly within FeatureStore reduced microservice network bandwidth, while payload format optimization and caching helped control dimensionality and serving costs.

**Tags:** [Machine Learning](https://yomu.fyi/topic/machine-learning), [Recommendation Systems](https://yomu.fyi/topic/recommendation-systems), [Scalability](https://yomu.fyi/topic/scalability), [Search](https://yomu.fyi/topic/search)

[Read original post](https://engblog.nextdoor.com/from-pre-trained-to-fine-tuned-nextdoors-path-to-effective-embedding-applications-3a13b56d91aa)
