← build log
ml in productionpattern 12ML in production

Embeddings as a candidate source, not a ranking signal

Feeding raw similarity into the ranking model makes it harder to say why anything ranked where it did.

The problem

Qdrant stores embeddings for content and can return nearest-neighbor similarity scores cheaply. It’s tempting to treat that score as one more input feature straight into the LightGBM ranking model, alongside social distance and interaction history — it’s already computed, it’s numeric, it plausibly correlates with relevance. The question is what that choice costs once the model is live and something needs debugging.

Approaches considered

Embedding similarity as a ranking feature. Add embedding_similarity to the feature vector passed to ml-service, computed by querying Qdrant during feature hydration for every candidate, regardless of where the candidate came from.

Embedding similarity as a re-ranking pass after scoring. Score candidates without it, then apply a secondary boost based on similarity to recent engagement. This adds a second, less principled ranking step that competes with the model’s own learned weighting.

Vector search as one of several candidate sources, with no similarity score passed downstream. Qdrant returns a set of candidate post IDs. Everything about how those candidates get ranked happens identically to candidates from any other source.

Trade-offs

Treating vector search purely as a candidate source means potentially relevant signal — the raw similarity score — never reaches the model directly. If similarity turns out to be a strong predictor on its own, the model has to rediscover that relationship through whatever features it does receive, rather than being handed it outright.

The decision

Qdrant is queried directly by recommendation-service as one of four parallel candidate sources. Its output is a set of post IDs, nothing else. No similarity score crosses into the feature vector sent to ml-service.

Why

Once a similarity score is one of several ranking inputs, “why did this post rank highly” stops having a clean answer — was it the graph signal, the trending momentum, or the raw distance number injected upstream? Keeping retrieval and ranking separate means every candidate, regardless of source, is scored by the same model on the same feature set, and a ranking explanation only ever has to account for features that mean the same thing for every candidate. It’s the same reasoning that led to calling Qdrant directly instead of through a dedicated vector-service — vector search is a source, not a special path, so it doesn’t get a special exemption from how candidates are scored either.

Implementation

// recommendation-service — Qdrant is queried for IDs only. The
// candidate carries no similarity score past this point.
func (r *RecommendationService) vectorCandidates(ctx context.Context, userID string) ([]Candidate, error) {
	userEmbedding, err := r.embeddingStore.GetUserEmbedding(ctx, userID)
	if err != nil {
		return nil, err
	}

	hits, err := r.qdrant.Search(ctx, &qdrant.SearchPoints{
		CollectionName: "post_embeddings",
		Vector:         userEmbedding,
		Limit:          50,
	})
	if err != nil {
		return nil, err
	}

	candidates := make([]Candidate, len(hits))
	for i, hit := range hits {
		// only the post ID crosses the boundary — hit.Score is
		// discarded here, deliberately.
		candidates[i] = Candidate{PostID: hit.Id, Source: "vector"}
	}
	return candidates, nil
}
# ml-service — feature hydration never sees a Qdrant-derived
# similarity value; every candidate's feature set looks the same
# regardless of which of the four sources produced it.
FEATURE_COLUMNS = ["social_distance", "interaction_score", "recency_hours"]