RAG & Retrieval

RAG Pipelines & Function Calling

How function calling lets an LLM use your RAG pipeline as a tool to answer compound questions.

Key takeaways

  • Function calling lets LLMs interface with the real world (web services, databases), use specialized tools (math calculators, currency converters), access domain-specific information models and ontologies, and orchestrate complex compound tasks by breaking them into smaller, composable pieces.
  • The mechanism works in three steps: describe each tool as a function (name, description, parameters); the LLM replies with a tool invocation when it needs one; the caller parses the response, runs the tool, and feeds the output back to the LLM. It's supported natively in OpenAI models from GPT-3.5 up and in Llama 3.1; Llama 3 needs careful prompt engineering.
  • Function calling is hard to get right (prompt engineering, composability, request/response formats, per-model error handling), so Dataworkz hides that complexity behind the scenes — users don't need to understand function calling to benefit, while Dataworkz still exposes meaningful configuration.
  • A key use case is the Compound Question Engine: typical RAG handles compound questions (e.g., comparing two companies' metrics across years) poorly because they don't map to specific vector-DB chunks. Taking inspiration from ReAct, Dataworkz makes the RAG pipeline a tool the LLM can call to answer sub-questions before composing the final answer.
  • Additional capabilities and explorations include a plugged-in Math tool for calculations, chat interfaces that build on conversation history, connecting enterprise data (e.g., order tracking, recommendations), performing actions/updates (e.g., a ticketing system), querying ontologies and glossaries, and Text2SQL — with Dataworkz metrics and the probe available for debugging pipelines.
On this pagesections

    Introduction

    Typical examples of function calling in cookbooks include the ability to make calls to do web search, get weather, get customer orders, etc. RAG Pipelines are Gen AI applications that enable LLMs to answer questions based on private data or data that the LLM has not seen before. It is a practical and powerful mechanism for enterprises to use their own data without having to go through expensive mechanisms such as training from scratch or fine-tuning an LLM.

    We can leverage RAG Pipelines to provide the LLM with up-to-date information as a part of a larger use-case. More specifically we will explore the possibilities of combining the power of the Dataworkz Platform and the Dataworkz RAG Builder into function calling.

    Function Calling

    Advantages

    Function Calling enables a number of capabilities for LLMs.

    • Interface with the real-world – call web services, query databases, etc
    • Provide specialized tools for domain specific tasks – e.g. math calculators, currency converters, etc
    • Provide access to domain specific information models, ontologies and glossaries
    • Allow orchestration and composability – It allows the LLM to achieve complex and compound tasks. Complex and compound tasks might require way too many instructions to be practical. With composition using function calling, the instructions to the outer LLM are limited to the LLM breaking down the task to smaller, manageable pieces and orchestrating to use tools with additional instructions to complete them

    Implementation

    Mechanism

    Fig 1: Function Calling with LLM

    As shown in Fig 1, Leveraging Function Calling with an LLM involves the following –

    • Describing the tool(s) invocation as a function call. Here you provide a descriptive name, a description of the tool, its parameters and any additional information the LLM might need to describe a function call
    • In the course of performing its task, if the LLM feels the need to use one of the provided tools, it replies with the tool invocation.
    • The caller should parse the LLM response and make the necessary tool invocation and provide the response back to the LLM in the next invocation so that the LLM can consume this output.

    LLM Support for Function Calling

    Function calling is supported in a variety of OpenAI models from GPT 3.5 upwards. Llama 3 does not natively support function calling but with careful prompt engineering, we have been able to get the Llama3-70B model to perform reasonably well. Llama 3.1 supports function calling natively.

    Complexity

    Function Calling can be complex to get right. It requires significant efforts to make it all come together with challenges in prompt engineering,  composability, request/response formats, error handling for each model amongst other things. In the Dataworkz Platform, we continue with our philosophy of allowing our users to take advantage of new Gen AI capabilities and to enable new, complex and exciting use-cases while still keeping the complexity under control.

    Dataworkz Platform and Function Calling

    Dataworkz is embracing the power of Function Calling and introducing it behind the covers in various use-cases which we discuss in this section. Dataworkz Platform and the Dataworkz RAG pipeline can be seen as tools that can be integrated into the LLM via this mechanism. This provides the LLM with access to proprietary data via the connectors in the Dataworkz platform as well as access to the powerful capabilities of the RAG pipeline over proprietary knowledge bases. We have built new capabilities with these integrations and we have a number of research threads in this space where we are experimenting with mechanisms that make it easier and more practical to use. We are also experimenting with what else we can do with it that will enable our users to do more with the technology.

    Use-cases

    Compound Question Engine

    Imagine that a user asks us questions like –

    • Compare the features of model X and model Y
    • Which of Apple and Tesla delivered a higher net earnings per share in 2022 and 2023?
    • Did the management team change between 2023 and 2024?

    The typical RAG pipeline of making semantic searches and then asking the LLM to generate an answer does not work very well when the user asks compound questions. The complex question does not translate well to specific chunks in the vector database that has the answer to the overall question. Compound questions such as those that compare two pieces of data – Which of Apple and Tesla delivered a higher net earnings per share in 2022 and 2023? may require retrieving sub-questions – What was Apple’s net earning per share in 2022? and What was Apple’s net earnings per share in 2023? and so on – separately before answering the original question. Taking inspiration from frameworks such as ReAct, we can leverage function calling where we make the Dataworkz RAG Pipeline a tool that the LLM can use to answer sub questions before answering the larger user query. This allows us to take advantage of composability, providing instructions specific to the task (and sub-task).

    An interesting choice is whether the RAG pipeline should provide the context as the output or the generated answer. We are currently experimenting with the choice of going with the generated answer to keep the outer context limited which allows for larger and more complex queries to be supported at the cost of additional LLM calls.

    Math

    LLMs can be poor at math and calculations. We can improve the LLMs ability to do calculations by providing it a math tool. This works especially well in the compound question scenario. We can also extend this to domain specific functions such as statistics or probability or financial calculations. Dataworkz currently plugs in a Math tool to enable calculations. We are exploring customer use-cases where we can expose this capability so it can be extended in domain specific ways.

    Chat

    A Chat interface provides a powerful user experience where the user builds upon the previous conversation with additional questions. It is a particularly popular and effective mechanism for users to interact with data. We leverage the Dataworkz RAG pipeline as a tool for the LLM to call in a chat conversation via function calling. When the user asks a question, the LLM is prompted to build upon the question based on the conversation history and leverage the Dataworkz RAG pipeline to find an answer from the data corpus. This allows the user to converse naturally with their proprietary, enterprise data.

    Enterprise Data

    Dataworkz Platform is a powerful enterprise data platform that brings in data from various sources. We are exploring use-cases with customers that enable bringing in this data in a Gen AI application powered by the Datawork RAG Builder. If we make the Dataworkz Platform data connectivity a tool that can be added to the LLM via function calling, we can imagine applications that leverage this proprietary, enterprise data in new and exciting ways.

    • Imagine an order tracking system that allows a user to query their order status in a chat application. This can be powered by an LLM with the Dataworkz Platform as a function called by the LLM along with Dataworkz RAG pipeline supporting the user with shipping policies and other static information
    • Imagine a recommendation system that the user can interact with that pulls in similar users and the products they purchased or browsed – again leveraging the Dataworkz RAG pipeline and the Dataworkz platform to enable these

    Other Possibilities

    Other advanced use-cases include being able to perform actions and updates to databases and systems via Gen AI applications. For example – Creating a ticketing system that leverages Dataworkz Platform and Dataworkz RAG pipeline to identify similar issues and solutions and adds a ticket only when the issue is completely new.

    Another area to explore is leveraging Dataworkz RAG pipeline to query Ontologies, Knowledge Bases and Glossaries for the LLM to understand domain specific terms.

    Leveraging Text2SQL capabilities as a function can allow LLMs to make database queries based on user interaction.

    Using Function Calling in Dataworkz

    As with other aspects of the GenAI space, our philosophy is to enable powerful advances in Gen AI in a manner that it is easily accessible to end users without requiring a significant and deep understanding of the underlying mechanics. To that end, Dataworkz follows an opinionated approach to integrating technology while still exposing meaningful configuration to control the workflow. Keeping to the same philosophy, Dataworkz hides the complexity of function calling – choosing the correct prompts, providing minimal configuration – to make the power available to our users.

    Users do not need to understand function calling in order to make use of it. Currently, function calling is seamlessly integrated behind the covers but as we work with customers exploring newer enterprise applications of this technology, we will also explore how we can practically expose this to our users.

    As always, all our metrics and our tools (such as the probe) are available with function calling to users to explore and debug their pipelines.

    Conclusion

    Function calling is a powerful composition technique allowing an LLM to handle much more complex tasks. Dataworkz Platform and Dataworkz RAG Pipelines can be integrated into an LLM as tools to take advantage of function calling. This enables access to the data configured in Dataworkz and enables more complex Gen AI applications to be created. Dataworkz is exploring the boundaries of this technology with a number of our early access customers to see what kind of applications it can power. Keep an eye on this space because function calling with Dataworkz has the ability to do some amazing things!

    Frequently asked questions

    What is function calling and why does it matter for LLMs?

    Function calling lets an LLM invoke external tools — calling web services, querying databases, using calculators, or accessing domain-specific information — and orchestrate complex compound tasks by breaking them into smaller, manageable, composable pieces.

    How does function calling work mechanically?

    You describe each tool to the LLM as a function with a name, description, and parameters. When the LLM needs a tool, it replies with the tool invocation; the caller parses that, makes the actual tool call, and returns the result to the LLM on the next invocation so the model can use the output.

    Which LLMs support function calling?

    OpenAI models from GPT-3.5 upward support it, and Llama 3.1 supports it natively. Llama 3 does not support it natively, but with careful prompt engineering the post reports getting the Llama3-70B model to perform reasonably well.

    How does Dataworkz use function calling?

    Dataworkz integrates the Dataworkz Platform and Dataworkz RAG pipeline as tools the LLM can call, giving the model access to proprietary data via platform connectors and to RAG over proprietary knowledge bases. The complexity is integrated behind the scenes so users can benefit without understanding the underlying mechanics.

    See what your engineers can ship in production

    Dataworkz is the agentic AI platform enterprises trust to put AI agents into production. Teams build production-ready agents in days, every decision stays traceable, and every agent has ROI attached.

    Explore the platform