Online-Optimized RAG for Tool Use and Function Calling

Yu Pan, Xiaocheng Li, Hanzhao Wang

TL;DR

Retrieval-Augmented Generation (RAG) for tool use often fails due to misaligned embeddings caused by poor documentation or imperfect models. This paper introduces Online-Optimized RAG (ORAG), a plug-and-play framework that continually updates tool embeddings at deployment time using simple binary feedback (like task success or failure). It achieves state-of-the-art retrieval accuracy with negligible latency overhead and requires absolutely no changes to the underlying Large Language Model (LLM).

What Problem Does This Paper Address?

When LLMs use external tools or APIs, they rely on a retriever to match the user's query to the right tool description within a vector space. However, in production, this retrieval often breaks down due to embedding misalignment. This happens when tool documentation is noisy or sparse, the embedding model is suboptimal, or user phrasing shifts over time.

Because traditional RAG pipelines freeze their embeddings after offline training, they cannot adapt to real-world failures. This leads to incorrect tool selection, causing the downstream LLM to fail the task or waste API calls backtracking.

Methods

The authors propose Online-Optimized RAG (ORAG). Instead of fine-tuning the query embedding model (which is often a black-box API) or modifying the LLM planner, ORAG dynamically updates the tool/item embeddings during live deployment.

Figure 2: Online-Optimized RAG updates tool embeddings at deployment time for each incoming query qt. When the selected tool it succeeds, its embedding moves toward the query to increase similarity. When it fails, the embedding of it moves away to reduce similarity. Embeddings of all unselected tools are also pushed away from the query. See Algorithm 1 and its discussion for details.
  • Bandit-Style Feedback: The system doesn't need to know the "ground truth" optimal tool. It only requires a binary signal indicating whether the selected tool succeeded or failed (e.g., via user thumbs up/down or automated unit tests).
  • Importance-Weighted Online Gradient Descent: When a tool is selected and succeeds, its vector is pulled closer to the query vector to increase future similarity. If it fails, it is pushed away. Crucially, the embeddings of unselected tools are also adjusted slightly away to maintain proper mathematical contrast across the softmax distribution.
  • Versatile Variants: The framework natively supports extensions like $K$-retrieval with an LLM reranker, time-varying databases (adding/removing tools dynamically), and multi-hop retrieval pipelines.

Datasets

The framework was evaluated across several challenging benchmarks:

  • Tool Use: UltraTool (complex real-world planning scenarios) and three sub-tasks from ToolRet (ToolRet-Web, ToolRet-Code, and ToolRet-Customized).
  • Information Retrieval: The FiQA benchmark.
  • Multi-Hop Reasoning: MultiHopRAG.

Key Insights and Ideas

  • Optimize the Catalog, Not the Model: Modifying the tool database embeddings rather than the query model is computationally lightweight and avoids degrading the query model's performance on other unrelated tasks.
  • Exploration-Free Learning: Unlike traditional multi-armed bandit algorithms that force random, explicit exploration (which hurts user experience), ORAG leverages the natural stochasticity of the retriever's softmax distribution.
  • Fixing Bad Models and Docs: The online updates can make a smaller, weaker embedding model perform comparably to a much larger model, and can effectively "repair" the performance loss caused by poorly written documentation.
Embedding repair for bad documentation and smaller models

Key Results

  • Consistent Accuracy Gains: Across all benchmarks, ORAG significantly boosted Recall@10 and NDCG@10. For instance, optimizing the weaker text-embedding-v4 model allowed it to outperform the raw, unoptimized text-embedding-3-large model on several tasks.
  • High Efficiency: Heavy cross-encoder rerankers drastically increase latency. In contrast, ORAG achieves comparable accuracy gains with almost zero inference latency overhead because the embedding updates happen via lightweight, post-interaction gradients.
Figure 3: Performance vs. time cost of different retrieval methods. The performance is the arithmetic average of R@10 results in Table 1, and the time cost is evaluated and recorded on the same GPU server. The embedding model time cost is obtained by using the Qwen3-Embedding-4B as the proxy.
  • Multi-Hop Success: In multi-hop settings (MultiHopRAG), integrating ORAG improved end-to-end question-answering accuracy from 0.55 to 0.68.

Limitations and Future Work

  • Hyperparameter Sensitivity: The performance depends on choosing an appropriate learning rate ($\eta$). While a standard time-varying schedule ($c/\sqrt{t}$) works well, automated tuning could make deployment even simpler.
  • Probability Calibration: The retrieval probabilities are directly tied to embedding scores; the authors note that incorporating formal calibration techniques could further refine retrieval confidence.
  • Feedback Complexity: The current model relies heavily on binary success/failure signals. Extending the framework to handle richer, nuanced, or delayed feedback remains an open area for future research.

Summary updated

BibTeX
@misc{pan2025online,
  author = {Yu Pan and Xiaocheng Li and Hanzhao Wang},
  title = {{Online-Optimized RAG for Tool Use and Function Calling}},
  year = {2025},
  eprint = {2509.20415},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.20415},
}
Figure