概述
由於項目向量可以預先計算並建立索引,雙塔模型支援在更詳細的排序階段之前進行可擴展的檢索。
深入探討
Recommendation systems often separate candidate retrieval from ranking. Retrieval narrows a large catalog to a manageable set of potentially relevant items. A two-tower model uses one encoder for the user or query and another for candidate items. Each tower transforms its own available features into a vector in a shared embedding space. A similarity function, often a dot product or cosine score, ranks candidate pairs. The two encoders can be run independently. Item embeddings may be calculated offline and stored in a nearest-neighbor index. At request time, the user tower creates a query vector and the index returns a shortlist. This separation supports large catalogs more efficiently than evaluating a deep joint model against every item. TensorFlow Recommenders describes this architecture as retrieval with query and candidate models. The independent structure creates a tradeoff. It scales retrieval, but it cannot directly model arbitrary pairwise interactions that require seeing the user and item together, unless those interactions are represented in the embedding training objective or features. A downstream ranker can combine retrieved candidates with richer context, cross-features and operational constraints. Retrieval recall matters: a ranker cannot select an item that was never retrieved. Training often uses positive interactions and sampled or in-batch negatives to shape the embedding space. The negative sampling strategy and exposure logs affect what the model learns. Evaluation should measure recall or ranking among a realistic candidate pool and check cold-start performance. Monitor embedding freshness, index refreshes and feature-version compatibility. A high similarity is a retrieval score, not a calibrated probability or proof of user preference. Eligibility, safety, diversity and policy constraints should be applied in the system design. The architecture makes large-scale search practical, while final user experience depends on candidate coverage, ranking quality and evaluation beyond offline similarity.
現實世界的實施
一個假設的音樂應用程式將聽眾最近的活動編碼為使用者向量,並將每首歌的元資料編碼為項目向量。最近鄰搜尋會檢索出向量相似的歌曲。
檢索服務會預先計算項目嵌入,並使用近似最近鄰索引進行搜尋,從而避免在請求時對每個使用者-項目對進行完整的神經網路評估。
排序模型隨後會考慮額外的配對特定上下文,例如當前會話、新鮮度和業務限制,這些是獨立塔架在檢索過程中可能無法捕捉到的。
團隊會檢查使用者和項目嵌入是否由相容的版本和維度產生;預處理不匹配或過時的項目向量可能會降低相似度分數。
雙塔推薦模型的未來
雙塔系統可以透過監控候選項目召回率、嵌入新鮮度和延遲,以及最終排序結果來變得更有用。團隊應將塔架和索引進行版本控制,並在重建檢索基礎設施之前測試特徵變更。隨著使用者和項目群體的成長,近似搜尋可以提高規模,但應針對樣本與精確檢索進行比對檢查。獨立的排序器可以在保留清晰檢索階段的同時增加上下文。報告應說明相似度如何產生候選項目,然後展示後續的篩選和排序如何影響使用者實際看到的內容。
付諸實踐
為什麼這很重要
- 成本與預算. 多年來,架構決策決定著效能和營運成本。
- 更明確的決策. 技術教育幫助團隊選擇正確的堆疊,而不僅僅是最新的堆疊。
- 品質管控. 更好的工程選擇可以減少生產中的可靠性事故。
留意
- 優化一項基準測試可以隱藏更廣泛的系統弱點。
- 基礎設施和維護成本常常被低估。
- 隨著系統變得更加複雜,安全性和可觀察性差距可能會擴大。
後續步驟
- 在實施之前定義延遲、品質和成本目標。
- 在實際負載和資料條件下進行基準測試。
- 儀器監控錯誤、漂移和使用者影響。
- 在擴展之前準備回滾和事件回應路徑。
不斷探索
常見問題
什麼是雙塔推薦模型?
雙塔推薦系統將使用者或查詢與每個候選項目分別編碼為向量,然後透過向量相似度對配對進行評分。由於項目向量可以預先計算並建立索引,雙塔模型支援在更詳細的排序階段之前進行可擴展的檢索。
在標準的兩塔推薦器中,每個塔會產生什麼?
兩個編碼器獨立地將查詢側和候選側特徵映射到共享向量空間。
為什麼可以預先計算項目嵌入?
由於項目向量是獨立計算的,因此可以離線產生它們並建立索引。
哪一種操作通常會從嵌入中檢索候選者?
向量索引支援對預先計算的項目嵌入進行相似性搜尋。
為什麼候選人回憶排名前很重要?
下游排名者只能看到檢索返回的候選者,因此無法在那裡恢復遺失的候選者。
哪些互動是獨立編碼的塔難以直接表示的?
獨立編碼有利於規模,但可能無法捕捉到需要雙方共同參與的豐富互動。