Traditional recommender systems rely on collaborative filtering and matrix factorization to surface items. These methods work well for dense interaction data, but they struggle with cold-start items, sparse user histories, and the rich unstructured metadata that drives modern catalogs. Large language models offer a unified alternative. They can encode semantic item descriptions, reason over long user sessions, and generate natural language explanations for every recommendation. For engineering teams building next-generation personalization pipelines, the shift is not just about model architecture, but about infrastructure that supports long-context inference and agentic loops without unpredictable costs.
Why LLMs for Recommendation and Personalization
LLMs bring several concrete advantages to recommender systems.
- Semantic understanding: A model can ingest product descriptions, reviews, and user-generated content without hand-engineered feature pipelines.
- Zero-shot transfer: New items or categories can be recommended immediately if the model understands their text descriptions, reducing cold-start latency.
- Multi-turn context: Conversational shopping assistants can maintain state across sessions, refining preferences dynamically.
- Explainability: Instead of opaque scores, the model can output reasoning such as "Recommended because you prefer minimalist running shoes under 100 dollars."
These capabilities turn the recommender from a static scoring engine into an interactive system that understands intent.
Architecture Patterns for LLM-Based Recommenders
Most production implementations fall into four patterns.
LLM as Feature Encoder
Use an LLM or embedding model to generate dense vectors for items and queries, then feed them into a traditional two-tower or factorization model. Oxlo.ai provides embedding endpoints for BGE-Large and E5-Large, which you can call through the standard OpenAI SDK and integrate into your existing retrieval stack.
LLM as Ranker
Retrieve a candidate set via vector search or heuristics, then prompt an LLM to score or reorder items based on the user's profile and recent behavior. This is where context windows and prompt length matter. Because Oxlo.ai uses request-based pricing rather than token-based metering, sending a long product catalog or extensive click history in the prompt does not inflate your inference cost.
Generative Recommendation
The model directly generates item identifiers, query refinements, or personalized marketing copy. This works best when the catalog is small or when the output is a natural language suggestion that maps to items downstream.
Agentic Recommender
The LLM acts as an agent with access to tools: search APIs, inventory databases, and user profile stores. It issues function calls to gather context, then synthesizes a final recommendation. Agentic workflows often require multiple turns and large context buffers, which can become expensive on token-based platforms. Oxlo.ai's flat per-request pricing is designed for exactly these workloads.
Prompt Engineering for Personalization
The quality of an LLM ranker depends on how you represent the user. A strong prompt typically includes:
- A structured user profile (demographics, explicit preferences, budget constraints).
- A chronologically ordered interaction history (views, purchases, returns).
- A candidate item list with attributes (title, category, price, description).
- An output schema, ideally enforced via JSON mode.
Long user histories and detailed catalogs produce prompts that can span tens of thousands of tokens. On token-based providers, this directly increases cost per recommendation. Oxlo.ai eliminates that variable. You pay one flat cost per API request regardless of prompt length, so you can pass full session contexts without tradeoffs.
Code Example: Candidate Ranking with Oxlo.ai
Below is a minimal Python example that ranks candidate products for a user. It uses the OpenAI SDK pointed at Oxlo.ai and requests a structured JSON response. We use Llama 3.3 70B, a strong general-purpose model for reasoning over structured context.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ.get("OXLO_API_KEY")
)
user_history = """
- Viewed: Wireless Noise-Cancelling Headphones (Sony WH-1000XM5)
- Purchased: USB-C Charging Cable (Anker, 6ft)
- Viewed: Mechanical Keyboard Keychron K8
"""
candidates = """
1. Keychron K8 Pro (Mechanical, RGB, Bluetooth)
2. Logitech MX Keys S (Wireless, low-profile)
3. Sony WH-CH720N (Noise-cancelling, budget tier)
4. Anker 737 Power Bank (24,000 mAh)
"""
prompt = f"""You are a personalized shopping assistant.
Based on the user's history and the candidate items below, rank the top 3 items and explain why each fits the user's preferences.
User History:
{user_history}
Candidate Items:
{candidates}
Respond in JSON with keys: rankings (array of objects with fields rank, item_id, reasoning)."""
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[{"role": "user", "content": prompt}],
response_format={"type": "json_object"}
)
print(response.choices[0].message.content)
Because Oxlo.ai is fully OpenAI SDK compatible, the only change needed is the base_url. You can switch between models such as Qwen 3 32B for multilingual users, DeepSeek R1 671B MoE for complex reasoning, or Kimi K2.6 for agentic coding and vision workflows without rewriting your client logic.
Embedding Retrieval and Filtering
Before you rank, you need candidates. Oxlo.ai offers embedding models including BGE-Large and E5-Large through the /embeddings endpoint. You can index product descriptions in a vector store, retrieve the top-k nearest neighbors for a user query, and then pass those candidates to an LLM ranker.
This two-stage architecture keeps latency low and quality high. The embedding step handles broad retrieval, while the LLM handles nuanced personalization. Because both stages are available on Oxlo.ai, you can standardize your infrastructure on a single provider and a single API shape.
Agentic Workflows and Tool Use
For advanced personalization, treat the LLM as an agent. Give it function definitions that query a user profile database, check inventory levels, or apply business rules like margin thresholds. The model decides which tools to call, then produces the final recommendation.
This pattern excels in marketing automation, where a single user request might trigger:
- A profile lookup.
- A search across three category indexes.
- A comparison of promotional eligibility.
- A draft of personalized email copy.
Each step adds tokens and API calls. On token-based platforms, agentic loops accumulate cost quickly. Oxlo.ai's request-based pricing can be significantly cheaper for these workloads because the price per call is fixed, even when prompts contain long tool definitions and conversation history. Models such as GLM 5, Qwen 3 32B, and DeepSeek V4 Flash with 1M context windows are well suited to maintaining state across extended agentic sessions.
Cost and Latency Considerations
Moving personalization to an LLM introduces two engineering constraints: cost predictability and serving latency.
Cost: Token-based pricing ties your bill to prompt length. Recommender prompts are inherently long because they must carry user histories, product metadata, and few-shot examples. Oxlo.ai uses flat per-request pricing, so your cost per recommendation is constant whether you send 1K tokens or 100K tokens. For teams running high-volume personalization or long-context agentic loops, this can yield substantial savings. See https://oxlo.ai/pricing for plan details.
Latency: Long prompts increase time-to-first-token. Mitigate this by:
- Using smaller, task-specific models for structured parsing (for example, Oxlo.ai Coder Fast or Qwen 3 Coder 30B).
- Streaming responses to the client so users see reasoning immediately.
- Caching frequent user profile summaries and retrieved candidates.
Oxlo.ai supports streaming, JSON mode, and function calling on its chat endpoints, and popular models are served with no cold starts, so you can optimize the user experience without leaving the platform.
Conclusion
LLMs are reshaping recommender systems from static matrix operations into dynamic, language-aware personalization engines. The infrastructure you choose determines whether that power is affordable at scale. Oxlo.ai provides a developer-first platform with request-based pricing, 45+ models across reasoning, code, vision, and embeddings, and full OpenAI SDK compatibility. If your pipelines rely on long user histories, agentic tool use, or high-volume candidate ranking, Oxlo.ai is built to keep costs flat and latency low.
Top comments (0)