Vector Search at Trendyol Search Core

Mert Bahardoğan20 Aug 2024

Problem

The Trendyol Search Core team wanted to show more personalized results and to support semantic search, so that users see the products they want higher in the list. Their search already ran on Elasticsearch with its own filtering logic and score-based sorting, and that logic had to keep working. A separate vector database would add an external dependency and a system without in-house know-how. The question was whether Elasticsearch itself could hold embeddings and score with them at acceptable query and indexing time.

Example from the article: a search request that is suitable for vector search goes through the usual query, and the top 100 hits are then re-scored by cosine similarity between the query embedding and each product embedding, returning the first 10.

Solution in brief

Store each product's embedding in a dense_vector field and keep the existing query as is. Add a rescore query that computes cosine similarity with a script_score on the top window_size hits only. The team already knew Elasticsearch, which was the deciding factor.

Questions this case answers
  • How to add embedding-based re-ranking to a production keyword search engine while keeping its existing filtering and scoring logic and avoiding a new datastore
  • How to add semantic or personalized vector scoring to an existing keyword product search without a separate vector database?
  • How to re-rank only the top search hits by embedding similarity in Elasticsearch?
  • How to store product embeddings in Elasticsearch and keep query latency under control?

Tools and methods

  • Elasticsearch — search engine and vector store (dense_vector field, script_score, rescore)
  • Rescore query — re-scores only the top window_size hits of the original query
  • Cosine similarity — similarity function, matched to the embedding model
  • Load testing — checks the system before the feature reaches production
Continue reading — it's free

Google or a one-time email code. No password.