<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: LangDB</title>
    <description>The latest articles on Forem by LangDB (@langdb).</description>
    <link>https://forem.com/langdb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F9154%2F5cb7baf7-f178-4aaa-81aa-77b9db1a9468.png</url>
      <title>Forem: LangDB</title>
      <link>https://forem.com/langdb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/langdb"/>
    <language>en</language>
    <item>
      <title>Designing Smart Multi-Agent Workflows with Agno &amp; LangDB</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Thu, 24 Jul 2025 14:48:53 +0000</pubDate>
      <link>https://forem.com/langdb/designing-smart-multi-agent-workflows-with-agno-langdb-nic</link>
      <guid>https://forem.com/langdb/designing-smart-multi-agent-workflows-with-agno-langdb-nic</guid>
      <description>&lt;p&gt;Build a multi-agent financial analysis team with &lt;a href="https://langdb.ai/" rel="noopener noreferrer"&gt;LangDB&lt;/a&gt; and &lt;a href="https://www.agno.com?utm_source=langdb&amp;amp;utm_medium=partner-content&amp;amp;utm_campaign=partner-technical&amp;amp;utm_content=langdb" rel="noopener noreferrer"&gt;Agno&lt;/a&gt; that can reason, research, and report on complex financial data.&lt;/p&gt;

&lt;p&gt;In the world of finance, staying ahead requires more than just data; it requires deep analysis, contextual awareness, and collaborative reasoning. What if you could build a team of AI agents to do this for you? In this post, we'll show you how to build a sophisticated, multi-agent financial analysis team using LangDB and Agno.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR:
&lt;/h2&gt;

&lt;p&gt;This guide walks you through building a multi-agent workflow using Agno for orchestration and LangDB as the AI Gateway. We'll use a financial analysis team as a practical example to show how you can build sophisticated agent systems that are easy to manage and debug, thanks to LangDB's end-to-end tracing, dynamic tooling, and access to over 350 LLMs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjksd9oiov7sxpqhxjdzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjksd9oiov7sxpqhxjdzm.png" alt="Full Conversation with Agn" width="800" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This team of agents collaborates to deliver in-depth insights on publicly traded companies by combining web research for market sentiment with hard financial data analysis. You can see a &lt;a href="https://app.langdb.ai/sharing/threads/630b2ded-15ae-43d9-8a7a-d6dd9d649655" rel="noopener noreferrer"&gt;full trace of the final agent's execution&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;You can find the complete source code for this project on GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LangDB Samples&lt;/strong&gt;: &lt;a href="https://github.com/langdb/langdb-samples/tree/main/examples/agno/reasoning-finance-team" rel="noopener noreferrer"&gt;https://github.com/langdb/langdb-samples/tree/main/examples/agno/reasoning-finance-team&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Architecture: A Trio of Financial Experts
&lt;/h2&gt;

&lt;p&gt;Our system is composed of two specialist agents orchestrated by a coordinating team:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Web Search Agent&lt;/strong&gt;: Gathers the latest news and market sentiment from the internet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Finance Agent&lt;/strong&gt;: Equipped with &lt;code&gt;YFinanceTools&lt;/code&gt; to fetch and analyze quantitative stock data, including pricing, fundamentals, and analyst recommendations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reasoning Finance Team&lt;/strong&gt;: A coordinator that directs the two agents, synthesizes their findings, and produces a final, comprehensive report.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;LangDB provides the backbone for this system. As an AI Gateway, it enables seamless access to over 350 LLMs, simplifies tool integration, and provides full end-to-end tracing and observability into each agent's actions and the team's collaborative process.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Checkout: &lt;a href="https://docs.agno.com/models/langdb" rel="noopener noreferrer"&gt;https://docs.agno.com/models/langdb&lt;/a&gt; and &lt;a href="https://docs.agno.com/observability/langdb" rel="noopener noreferrer"&gt;https://docs.agno.com/observability/langdb&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Enhanced Tracing with &lt;code&gt;pylangdb.agno.init()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;While you can use LangDB as a provider in Agno directly, calling &lt;code&gt;pylangdb.agno.init()&lt;/code&gt; unlocks deeper, end-to-end tracing. This function provides additional metadata and observability by automatically instrumenting the entire Agno framework, giving you complete visibility into your agent's workflows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# main.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pylangdb.agno&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize LangDB for enhanced tracing *before* importing any Agno modules.
&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;agno.agent&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Agent&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;agno.team&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Team&lt;/span&gt;
&lt;span class="c1"&gt;# ... other imports
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As an official provider integrated with Agno, LangDB requires you to set up your credentials. You'll need to export your LangDB API key and Project ID as environment variables. You can find these in your &lt;a href="https://app.langdb.ai/settings/api_keys" rel="noopener noreferrer"&gt;LangDB project settings&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;LANGDB_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;your_langdb_api_key&amp;gt;"&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;LANGDB_PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;your_langdb_project_id&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough: Building the Team
&lt;/h2&gt;

&lt;p&gt;Let's look at how the agents and the team are defined.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Web Search Agent: Decoupled and Dynamic
&lt;/h3&gt;

&lt;p&gt;Instead of hard-coding a search tool, we assign the &lt;code&gt;web_agent&lt;/code&gt; a LangDB Virtual Model. This decouples the agent's logic from the specific tools it uses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;web_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Web Search Agent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Search the web for the information&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;LangDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;langdb/search_agent_xmf4v5jk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Always include sources&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This virtual model is configured in the LangDB UI to provide search capabilities, which we'll cover in the next section.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Finance Agent: The Quantitative Analyst
&lt;/h3&gt;

&lt;p&gt;This agent is equipped with &lt;code&gt;YFinanceTools&lt;/code&gt; to access a wide range of financial data. It's powered by a powerful model like Grok-4 and has specific instructions to format its output professionally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;finance_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Finance AI Agent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Analyse the given stock&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;LangDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xai/grok-4&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;YFinanceTools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;stock_price&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;stock_fundamentals&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;analyst_recommendations&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;company_info&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;company_news&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="p"&gt;)],&lt;/span&gt;
    &lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Use tables to display stock prices, fundamentals (P/E, Market Cap), and recommendations.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Clearly state the company name and ticker symbol.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Focus on delivering actionable financial insights.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Coordinating Team: The Orchestrator
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://docs.agno.com/teams/introduction" rel="noopener noreferrer"&gt;&lt;code&gt;ReasoningFinanceTeam&lt;/code&gt;&lt;/a&gt; orchestrates the two specialist agents. It operates in &lt;code&gt;coordinate&lt;/code&gt; mode, allowing it to delegate tasks, synthesize information, and ensure the final output is a comprehensive report.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;reasoning_finance_team&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Team&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Reasoning Finance Team&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coordinate&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;LangDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xai/grok-4&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;web_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;finance_agent&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;ReasoningTools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;add_instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
    &lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Collaborate to provide comprehensive financial and investment insights&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Consider both fundamental analysis and market sentiment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Present findings in a structured, easy-to-follow format&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;success_criteria&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The team has provided a complete financial analysis with data, visualizations, risk assessment, and actionable investment recommendations.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;a href="https://docs.langdb.ai/concepts/virtual-models" rel="noopener noreferrer"&gt;Dynamic Tooling with Virtual Models and Virtual MCPs&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;To empower the &lt;code&gt;web_agent&lt;/code&gt; with live web search capabilities without hard-coding tools, we configure a Virtual Model in LangDB. This model is backed by a Virtual MCP Server that provides the actual search functionality.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Virtual MCP Server&lt;/strong&gt;: In the LangDB UI, create a new Virtual MCP Server named &lt;code&gt;web-search-mcp&lt;/code&gt; that uses the Tavily Search MCP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create and Configure the Virtual Model&lt;/strong&gt;: Create a new virtual model (e.g., &lt;code&gt;search-agent&lt;/code&gt;) and attach the &lt;code&gt;web-search-mcp&lt;/code&gt; to it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the Virtual Model ID&lt;/strong&gt;: Copy the ID of your new virtual model and use it in the &lt;code&gt;web_agent&lt;/code&gt; definition.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This setup allows you to change the tools and models your agents use on the fly from the LangDB UI, without changing a single line of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Team and Observing the Results
&lt;/h2&gt;

&lt;p&gt;To run the team, simply call the &lt;code&gt;print_response&lt;/code&gt; method with a detailed prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;reasoning_finance_team&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Compare the tech sector giants (AAPL, GOOGL, MSFT) performance:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;
    1. Get financial data for all three companies&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;
    2. Analyze recent news affecting the tech sector&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;
    3. Calculate comparative metrics and correlations&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;
    4. Recommend portfolio allocation weights&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every execution is captured in LangDB, providing a complete trace of the team's operations. This includes the initial prompt, each agent's contributions, the tools they used, and the final synthesized output. You can explore the &lt;a href="https://app.langdb.ai/sharing/threads/73c91c58-eab7-4c6b-afe1-5ab6324f1ada" rel="noopener noreferrer"&gt;full, shareable trace&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is a snippet of the final report generated by the agent team:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                   Comprehensive Comparative Analysis of Tech Giants: AAPL, GOOGL, and MSFT                    ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

As the Reasoning Finance Team, we've conducted a thorough analysis of Apple Inc. (AAPL), Alphabet Inc. (GOOGL), and Microsoft Corporation (MSFT) based on the user's request. This includes financial data retrieval, recent news analysis, comparative metrics and correlations, and portfolio allocation recommendations. Our evaluation incorporates fundamental analysis (e.g., valuations, growth), market sentiment (e.g., news and analyst views), quantitative metrics (e.g., betas, correlations), and risk assessments. Data is current as of July 2025.

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────

                                             1. Financial Data Overview                                             

Key financial data for each company, sourced from reliable APIs.                                                  

                                                   Stock Prices                                                   

   Metric               AAPL      GOOGL     MSFT                                                                   
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━                                                               
   Current Price        $210.16   $182.97   $505.62                                                                
   52-Week High         $260.10   $207.05   $508.30                                                                
   52-Week Low          $169.21   $140.53   $344.79                                                                
   50-Day Moving Avg    $203.87   $170.88   $472.41                                                                
   200-Day Moving Avg   $222.55   $173.43   $427.18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's a view of the full trace in the LangDB UI, showing how the agents collaborated to produce the report.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1vteghelrwbyevr311m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1vteghelrwbyevr311m.png" alt="LangDB trace view for the financial agent" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Full Observability with LangDB Tracing
&lt;/h2&gt;

&lt;p&gt;The "full observability" promised in our subtitle is delivered through LangDB's detailed tracing capabilities. When you run your Agno team, every action is captured, providing a transparent, hierarchical view of the entire workflow. Here’s what you can see in the trace:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hierarchical Span View&lt;/strong&gt;: The trace isn't a flat list of events but a tree of "spans." The top-level span represents the entire team's execution, with child spans for each agent's turn, tool call, and model invocation. This shows the exact flow of control and delegation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Input/Output for Each Step&lt;/strong&gt;: For every span, you can inspect the exact inputs and outputs. This means you can see the precise query sent to the &lt;code&gt;Web Search Agent&lt;/code&gt;, the articles it returned, the data requested by the &lt;code&gt;Finance Agent&lt;/code&gt;, and the final synthesized response from the team. This level of detail is crucial for debugging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Latency and Performance&lt;/strong&gt;: Each span is timestamped and includes latency information, allowing you to instantly identify bottlenecks. You can see exactly how long each tool call, model response, or agent deliberation took.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost and Token Usage&lt;/strong&gt;: For every LLM call, the trace displays the number of input and output tokens and the associated cost, giving you full transparency into your operational expenses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automatic Metadata&lt;/strong&gt;: Thanks to &lt;code&gt;pylangdb.agno.init()&lt;/code&gt;, traces are automatically enriched with metadata, including agent names, the team name (&lt;code&gt;Reasoning Finance Team&lt;/code&gt;), and the models used, making it easy to filter and search for specific traces in the LangDB UI.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This granular, end-to-end visibility is what makes building, debugging, and managing complex agentic workflows with LangDB and Agno so powerful.&lt;/p&gt;

&lt;p&gt;You can check out the full conversation with tracing here: &lt;a href="https://app.langdb.ai/sharing/threads/630b2ded-15ae-43d9-8a7a-d6dd9d649655" rel="noopener noreferrer"&gt;https://app.langdb.ai/sharing/threads/630b2ded-15ae-43d9-8a7a-d6dd9d649655&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By combining Agno with the LangDB AI Gateway, we've built a financial analysis team that is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modular&lt;/strong&gt;: Each agent has a specific, firewalled responsibility.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic&lt;/strong&gt;: We can change models and grant new tools on the fly from the LangDB UI without redeploying our agent.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observable&lt;/strong&gt;: We get detailed traces of every interaction, making debugging and performance analysis straightforward.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture allows for rapid development and iteration, enabling you to build truly powerful and intelligent agentic systems for any domain.&lt;/p&gt;

&lt;p&gt;Ready to build your own? &lt;a href="https://app.langdb.ai/" rel="noopener noreferrer"&gt;Start building for free on LangDB&lt;/a&gt; or Explore &lt;a href="https://www.agno.com?utm_source=langdb&amp;amp;utm_medium=partner-content&amp;amp;utm_campaign=partner-technical&amp;amp;utm_content=langdb" rel="noopener noreferrer"&gt;Agno&lt;/a&gt; to orchestrate your agent workflows.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>agno</category>
      <category>ai</category>
      <category>phidata</category>
    </item>
    <item>
      <title>Discover End-to-End Tracing on Google ADK with LangDB</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Mon, 07 Jul 2025 04:25:59 +0000</pubDate>
      <link>https://forem.com/langdb/discover-end-to-end-tracing-on-google-adk-with-langdb-7g2</link>
      <guid>https://forem.com/langdb/discover-end-to-end-tracing-on-google-adk-with-langdb-7g2</guid>
      <description>&lt;p&gt;Before diving into the code, watch this 2-minute video to see a complete demonstration of what we'll be building. You'll learn how to integrate LangDB tracing into the Google ADK Travel Concierge sample with no code chages.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/5tyDi5xzOUE"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this quick demo you’ll see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How to install and initialize the &lt;code&gt;pylangdb[adk]&lt;/code&gt; package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The single line of code that enables full observability for every ADK agent and tool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running a sample prompt like “Find me flights from JFK to London”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inspecting your workflow in the LangDB AI Gateway dashboard, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Threads view for step-by-step conversation logs.&lt;/li&gt;
&lt;li&gt;Traces view for Gantt charts, cost &amp;amp; token breakdowns, and dependency graphs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Drilling into any agent or tool (like the &lt;code&gt;planning_agent&lt;/code&gt; on Claude 3 Sonnet) for full observability.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In this tutorial, we'll walk through the architecture of a sophisticated Travel Concierge agent built with Google's Agent Development Kit (ADK). We'll explore how to leverage the LangDB AI Gateway to use any LLM—from OpenAI, Google, Anthropic, and more—and harness powerful features like Virtual Models and Virtual MCPs (Model Context Protocol) to create a dynamic, observable, and easily maintainable agent system.&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;travel_concierge&lt;/code&gt; agent is not just a single agent; it's a hierarchy of specialized sub-agents that handle everything from vacation inspiration to booking and in-trip assistance. Here's a look at the overall architecture:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmzyccv49g87e31zq622t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmzyccv49g87e31zq622t.png" alt="Travel Concierge's Multi-Agent Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project is based on the official &lt;a href="https://github.com/google/adk-samples/tree/main/python/agents/travel-concierge" rel="noopener noreferrer"&gt;Google ADK Travel Concierge sample&lt;/a&gt; and has been modified to showcase the integration with the LangDB AI Gateway.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can find the complete source code for this agent on GitHub: &lt;a href="https://github.com/langdb/langdb-samples/tree/main/examples/google-adk/travel-concierge" rel="noopener noreferrer"&gt;LangDB Samples&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Magic Behind the Curtain: &lt;code&gt;pylangdb.adk.init()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;First, let's talk about the most important line of code in this integration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# travel_concierge/agent.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pylangdb.adk&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;
&lt;span class="c1"&gt;# Initialize LangDB *before* importing any ADK modules.
&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This single function call is the key to unlocking the LangDB AI Gateway's observability features. By placing it at the very top of our script, before any &lt;code&gt;google.adk&lt;/code&gt; modules are imported, we enable automatic instrumentation for the entire agent framework.&lt;/p&gt;

&lt;p&gt;Here’s what &lt;code&gt;init()&lt;/code&gt; does automatically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Discovers Agents&lt;/strong&gt;: It recursively finds all agent and sub-agent definitions within your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Patches Runtimes&lt;/strong&gt;: It automatically patches the necessary ADK components to emit traces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Links Sessions&lt;/strong&gt;: It intelligently links all the interactions—from the root agent's initial processing to the deepest sub-agent and tool calls—into a single, cohesive trace in the LangDB Tracing.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This "zero-instrumentation" approach means you get complete, end-to-end visibility into your agent's complex workflows just by adding that one line of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Architecture: Root Agent and Sub-Agents
&lt;/h2&gt;

&lt;p&gt;Our &lt;code&gt;travel_concierge&lt;/code&gt; is a hierarchical agent. At the top is the &lt;code&gt;root_agent&lt;/code&gt;, which acts as a smart router or orchestrator. Its job is not to answer queries directly, but to delegate them to a specialized sub-agent.&lt;/p&gt;

&lt;p&gt;Here's its actual definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# travel_concierge/agent.py
&lt;/span&gt;&lt;span class="n"&gt;root_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;openai/gpt-4.1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;root_agent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A Travel Conceirge using the services of multiple sub-agents&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;instruction&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ROOT_AGENT_INSTR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sub_agents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;inspiration_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;planning_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;# ... and other sub-agents
&lt;/span&gt;    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="c1"&gt;# ...
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it uses a standard model (&lt;code&gt;"openai/gpt-4.1"&lt;/code&gt;) and has a list of &lt;code&gt;sub_agents&lt;/code&gt;. It doesn't have any tools of its own. The real power comes from the sub-agents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Tooling with Virtual Models and Virtual MCPs
&lt;/h2&gt;

&lt;p&gt;A LangDB Virtual Model is a powerful abstraction that decouples your agent's code from its runtime configuration. It acts as a pointer to a configuration that you can manage entirely from the LangDB UI.&lt;/p&gt;

&lt;p&gt;This is where the &lt;strong&gt;Model Context Protocol (MCP)&lt;/strong&gt; comes in. MCP is a standard that allows language models to interact with external tools and services in a uniform way. However, managing connections to multiple MCP-enabled tools can be complex.&lt;/p&gt;

&lt;p&gt;The LangDB AI Gateway simplifies this with &lt;a href="https://blog.langdb.ai/what-are-virtual-mcp-servers" rel="noopener noreferrer"&gt;&lt;strong&gt;Virtual MCP Servers&lt;/strong&gt;&lt;/a&gt;. A Virtual MCP is a single, managed endpoint that you configure in the UI. It can bundle multiple tools (like Google Maps, Tavily Search, or your own custom APIs), handle their authentication securely, and lock them to specific versions.&lt;/p&gt;

&lt;p&gt;You then connect this Virtual MCP to your agent's Virtual Model. This is how you can dynamically grant new capabilities to your agents without changing a single line of code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fahjelctldqrbzcrq2k3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fahjelctldqrbzcrq2k3e.png" alt="Virtual Models on LangDB"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are all the virtual models for our project, as seen in the LangDB AI Gateway dashboard. You can see the &lt;code&gt;inspiration_agent&lt;/code&gt;, &lt;code&gt;google_search_agent&lt;/code&gt;, and &lt;code&gt;planning_agent&lt;/code&gt; all configured here, ready to be assigned to our agents.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: The &lt;code&gt;inspiration_agent&lt;/code&gt; and Google Maps
&lt;/h3&gt;

&lt;p&gt;Let's look at our &lt;code&gt;inspiration_agent&lt;/code&gt;. It needs access to location data to give travel ideas. Instead of hardcoding a &lt;a href="https://app.langdb.ai/mcp-servers/google-maps" rel="noopener noreferrer"&gt;Google Maps MCP&lt;/a&gt;, we use a Virtual Model.&lt;/p&gt;

&lt;p&gt;Here's the agent's definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# travel_concierge/sub_agents/inspiration/agent.py
&lt;/span&gt;&lt;span class="n"&gt;inspiration_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;langdb/inspiration_agent_z73m3wmd&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;inspiration_agent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A travel inspiration agent...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;# ...
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice its model is &lt;code&gt;langdb/inspiration_agent_z73m3wmd&lt;/code&gt;. In the LangDB AI Gateway UI, we've configured this virtual model to use a &lt;strong&gt;Virtual MCP server&lt;/strong&gt; that has the Google Maps API attached as a tool. Now, when the &lt;code&gt;inspiration_agent&lt;/code&gt; is active, it can seamlessly query Google Maps, even though the tool isn't explicitly listed in its code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Grounding with Google Search
&lt;/h3&gt;

&lt;p&gt;We also have a specialized agent tool for web searches, &lt;code&gt;google_search_grounding&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# travel_concierge/tools/search.py
&lt;/span&gt;&lt;span class="n"&gt;_search_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;langdb/google_search_agent_hsz7lf9q&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;google_search_grounding&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;An agent providing Google-search grounding capability&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;# ... instruction ...
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;google_search_grounding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AgentTool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;_search_agent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like our &lt;code&gt;inspiration_agent&lt;/code&gt;, the &lt;code&gt;_search_agent&lt;/code&gt; uses a virtual model, &lt;code&gt;langdb/google_search_agent_hsz7lf9q&lt;/code&gt;. We've attached a &lt;strong&gt;Virtual MCP server&lt;/strong&gt; that provides the Tavily Search tool to this model in LangDB.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: The &lt;code&gt;planning_agent&lt;/code&gt; for Flights and Hotels
&lt;/h3&gt;

&lt;p&gt;Finally, let's look at the &lt;code&gt;planning_agent&lt;/code&gt;, which handles the core booking tasks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# travel_concierge/sub_agents/planning/agent.py
&lt;/span&gt;&lt;span class="n"&gt;planning_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;langdb/planning_agent_w1l8sygt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;planning_agent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Helps users with travel planning...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;# ...
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This agent's virtual model, &lt;code&gt;langdb/planning_agent_w1l8sygt&lt;/code&gt;, is connected to a Virtual MCP that provides an Airbnb search tool. This allows the agent to handle complex booking-related queries by leveraging this external service, all without having the tool logic hardcoded in the agent's definition.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Flow: From Query to Answer
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A user asks the &lt;code&gt;travel_concierge&lt;/code&gt;: "What are some good museums to visit in Paris?"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;root_agent&lt;/code&gt; receives the query and, based on its instructions, delegates the task to the &lt;code&gt;inspiration_agent&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;inspiration_agent&lt;/code&gt; is activated. Its virtual model configuration is loaded from the LangDB AI Gateway.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The agent now knows it has access to the Google Maps tool (via its Virtual MCP).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses the tool to find museums in Paris and provides a list to the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All of these steps—the delegation, the model calls, the tool usage—are automatically captured as traces in the LangDB AI Gateway, giving us complete observability into our agent's behavior.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can explore a complete, shareable trace of a conversation with this agent here: &lt;a href="https://app.langdb.ai/sharing/threads/8425e068-77de-4f41-8aa9-d1111fc7d2b7" rel="noopener noreferrer"&gt;https://app.langdb.ai/sharing/threads/8425e068-77de-4f41-8aa9-d1111fc7d2b7&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you open the trace, you'll see a detailed breakdown of the entire workflow. This includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A Gantt chart&lt;/strong&gt; visualizing the sequence and duration of each agent and tool invocation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost and token counts&lt;/strong&gt; for every LLM call, helping you monitor usage and optimize performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Detailed input/output payloads&lt;/strong&gt; for each step, allowing you to inspect the exact data being passed between components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A dependency graph&lt;/strong&gt; showing how agents and tools are interconnected, making it easy to debug complex interactions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqf1qszd4p9rdmcj0dy8l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqf1qszd4p9rdmcj0dy8l.png" alt="Screenshot of a LangDB trace showing the root_agent delegating to inspiration_agent and the tool call to Google Maps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By combining Google ADK with the LangDB AI Gateway's virtual models and MCPs, we've built a &lt;code&gt;travel_concierge&lt;/code&gt; agent that is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modular&lt;/strong&gt;: Each sub-agent has a specific responsibility.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic&lt;/strong&gt;: We can change models and grant new tools on the fly from the LangDB UI without redeploying our agent.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observable&lt;/strong&gt;: We get detailed traces of every interaction, making debugging and performance analysis easy.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture allows for rapid development and iteration, enabling us to build truly powerful and intelligent agentic systems.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Ready to build your own?&lt;/em&gt; &lt;a href="https://docs.langdb.ai/" rel="noopener noreferrer"&gt;&lt;em&gt;Check out the LangDB AI Gateway documentation to get started&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>adk</category>
      <category>ai</category>
      <category>python</category>
      <category>coding</category>
    </item>
    <item>
      <title>Choose the right AI model: Comparision of gpt-4o, claude and gemini using LangDB</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Thu, 27 Feb 2025 11:49:55 +0000</pubDate>
      <link>https://forem.com/langdb/choose-the-right-ai-model-comparision-of-gpt-4o-claude-and-gemini-using-langdb-1hic</link>
      <guid>https://forem.com/langdb/choose-the-right-ai-model-comparision-of-gpt-4o-claude-and-gemini-using-langdb-1hic</guid>
      <description>&lt;p&gt;Wondering which model to pick for your AI integration? It often comes down to response quality, time, and cost. LangDB’s &lt;strong&gt;Chat&lt;/strong&gt; lets you compare GPT, Claude, and Gemini and many other models side by side:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Send identical prompts to all three models in one interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Analyze response accuracy, coherence, and tone.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Measure execution time, latency, and cost.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Chat Interface in LangDB
&lt;/h2&gt;

&lt;p&gt;Query: &lt;em&gt;"Summarize the potential risks and benefits of AI-driven automated trading in financial markets, focusing on efficiency, transparency, and ethical concerns."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8mqc7uqibtlknsaqj9j2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8mqc7uqibtlknsaqj9j2.png" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LangDB provides detailed insights into the API calls made to various providers. Here's an example of a traces in LangDB:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Execution Time&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Cost&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GPT-4o&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;12.44 sec&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.637&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Claude 3.5 Sonnet&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;11.40 sec&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.013&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Gemini 1.5 Pro&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;7.47 sec&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.384&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These metrics allow developers to track performance, latency, and associated costs for each model efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Supported Models
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskkdmerq4ub8dehxcgvv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskkdmerq4ub8dehxcgvv.png" alt="Model Selection Drop Down" width="516" height="594"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Perform Model Comparisons?
&lt;/h2&gt;

&lt;p&gt;Directly comparing LLMs helps developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Select the Best Model:&lt;/strong&gt; Choose the model that performs best for your specific use case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimize Costs and Performance:&lt;/strong&gt; Compare API costs, execution times, and token efficiency.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;LangDB’s &lt;strong&gt;Chats&lt;/strong&gt; feature eliminates the operational friction of testing models. It provides a clean, user-friendly platform for experimenting with the latest AI models without any extra configuration.&lt;/p&gt;




&lt;h2&gt;
  
  
  Get Started with LangDB
&lt;/h2&gt;

&lt;p&gt;Stop guessing which model works best—test them side by side with LangDB &lt;strong&gt;Chats&lt;/strong&gt;. Compare the latest and best AI models effortlessly, optimize performance, and unlock new possibilities without writing or managing infrastructure.&lt;/p&gt;

&lt;p&gt;Start building smarter AI systems today—and let LangDB handle the heavy lifting.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>openai</category>
      <category>gemini</category>
      <category>sonnet</category>
    </item>
    <item>
      <title>How to Integrate LangChain with LangDB</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Thu, 27 Feb 2025 11:06:50 +0000</pubDate>
      <link>https://forem.com/langdb/how-to-integrate-langchain-with-langdb-55o4</link>
      <guid>https://forem.com/langdb/how-to-integrate-langchain-with-langdb-55o4</guid>
      <description>&lt;p&gt;LangDB integrates seamlessly with libraries like LangChain to provide advanced tracing and logging support for workflows, allowing developers to streamline the development process while maintaining detailed logs. If you're familiar with LangChain, adding LangDB to your workflow can offer enhanced functionality without adding complexity.&lt;/p&gt;

&lt;p&gt;In this blog post, we'll walk through how to use LangDB with LangChain, including a practical example. By the end, you'll understand how to capture detailed logs and take advantage of LangDB’s features in your own LangChain projects.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pre-requisites
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tavily API token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OpenAI API token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Python v3.11&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pip packages: langchain (at least v0.1.0), openai, wikipedia, langchain-community, tavily-python, langchainhub, langchain-openai, python-dotenv&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;langchain wikipedia langchain-community tavily-python langchainhub langchain-openai openai python-dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example: Using LangDB with LangChain
&lt;/h3&gt;

&lt;p&gt;Below is an example of how you can integrate LangDB into your LangChain workflow. The integration is designed to be as simple as possible, letting you focus on writing logic without worrying about setup complexities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hub&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.agents&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;AgentExecutor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;create_tool_calling_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_openai&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ChatOpenAI&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_community.agent_toolkits.load_tools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_tools&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_community.tools.tavily_search.tool&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;TavilySearchResults&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_community.utilities.tavily_search&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;TavilySearchAPIWrapper&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;


&lt;span class="n"&gt;api_base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.us-east-1.langdb.ai&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;### LangDB API base URL
&lt;/span&gt;&lt;span class="n"&gt;pre_defined_run_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;default_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;x-project-id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xxxxx&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;### LangDB Project ID
&lt;/span&gt;    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;x-thread-id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pre_defined_run_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xxxx&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;### LangDB API key
&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TAVILY_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tvly-xxxx&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_function_tools&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;search&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TavilySearchAPIWrapper&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;tavily_tool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TavilySearchResults&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_wrapper&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tavily_tool&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;load_tools&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wikipedia&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;init_action&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ChatOpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gpt-4o-mini&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;openai_api_base&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;api_base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;default_headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;default_headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;disable_streaming&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hwchase17/openai-functions-agent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_function_tools&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_tool_calling_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;agent_executor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AgentExecutor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;agent_executor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;input&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Who is the owner of Tesla company? Let me know details about owner.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nf"&gt;init_action&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We define an API base URL for LangDB (&lt;code&gt;api_base&lt;/code&gt;), which points to the LangDB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We add a &lt;code&gt;project-id&lt;/code&gt; to the headers to specify the LangDB project being used, and a &lt;code&gt;thread-id&lt;/code&gt; to create a unique thread for tracking and logging the execution within LangDB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once executed, the agent is able to process an input query ("Who is the owner of Tesla company? Let me know details about owner.") and use the tools integrated into the agent, like Tavily search and Wikipedia.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dynamic Model Switching
&lt;/h3&gt;

&lt;p&gt;One of LangDB’s most powerful features is the ability to seamlessly switch between different models without major changes in the existing codebase. In the above example, if you want to use Claude 3.5 Sonnet, all you need to do is update the model name in your configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Switch to Anthropic's Claude model
&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ChatOpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;claude-3-sonnet-20240229&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# Change model here
&lt;/span&gt;    &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;openai_api_base&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;api_base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;default_headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;default_headers&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this small change, LangDB takes care of the rest, ensuring that your application can dynamically adapt to new models without the need for rewriting large parts of your codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tracing in LangDB
&lt;/h3&gt;

&lt;p&gt;LangDB’s tracing feature provides real-time visualizations of your AI workflows, breaking down the time spent in each stage. The trace shows key stages like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Invoke:&lt;/strong&gt; Total time for the request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Model Call:&lt;/strong&gt; Time spent interacting with the model.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tool Usage:&lt;/strong&gt; Duration of specific tool calls.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trace visualization below highlights these stages, helping you identify bottlenecks and optimize your workflow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgb7tgq8ny7pzf14hdkd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgb7tgq8ny7pzf14hdkd.png" alt="The image shows two performance traces for " width="755" height="736"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This detailed view makes it easier to diagnose performance issues and fine-tune your LangChain integrations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using LangDB with LangChain is a powerful yet straightforward way to manage and trace your AI workflows. By leveraging LangDB’s capabilities, you can focus on developing complex workflows without worrying about the operational overhead. The ability to seamlessly switch between models also ensures that you can stay agile as new AI technologies emerge.&lt;/p&gt;

&lt;p&gt;Start integrating LangDB with LangChain today, and enjoy the flexibility and scalability it offers; Check out &lt;a href="https://langdb.ai/" rel="noopener noreferrer"&gt;LangDB&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>langchain</category>
    </item>
    <item>
      <title>Why We Built an AI Gateway in Rust: A Performance-Centric Decision</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Thu, 13 Feb 2025 18:44:14 +0000</pubDate>
      <link>https://forem.com/langdb/why-we-built-an-ai-gateway-in-rust-a-performance-centric-decision-2nb8</link>
      <guid>https://forem.com/langdb/why-we-built-an-ai-gateway-in-rust-a-performance-centric-decision-2nb8</guid>
      <description>&lt;p&gt;When building our AI gateway, we knew performance would be a critical factor. Unlike most AI software written in Python, an AI gateway acts as the &lt;strong&gt;proxy layer&lt;/strong&gt; between users and inference engines. This gateway must handle &lt;strong&gt;high concurrency&lt;/strong&gt;, &lt;strong&gt;low latency&lt;/strong&gt;, and &lt;strong&gt;large data volumes&lt;/strong&gt; efficiently. Python, while dominant in the AI ecosystem, struggles under these demands due to its &lt;strong&gt;runtime overhead&lt;/strong&gt; and limitations with concurrency.&lt;/p&gt;

&lt;p&gt;To demonstrate why we chose &lt;strong&gt;Rust&lt;/strong&gt;, we benchmarked three popular programming environments—&lt;strong&gt;Rust&lt;/strong&gt;, &lt;strong&gt;Python&lt;/strong&gt;, and &lt;strong&gt;JavaScript (Node.js)&lt;/strong&gt;—to evaluate their performance under high-load conditions. Rust emerged as the clear winner, offering predictable and stable performance even at scale.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benchmark Setup: Simulating Real-World AI Traffic
&lt;/h3&gt;

&lt;p&gt;We built an &lt;strong&gt;HTTP/2 streaming server&lt;/strong&gt; and a corresponding client to mimic real-world AI workloads. Here’s how the setup worked:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Streams &lt;strong&gt;tokens at a fixed inter-token latency of 25ms&lt;/strong&gt;, similar to the tokenized output of an AI inference engine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uses HTTP/2 to deliver tokenized data efficiently to multiple clients.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implements asynchronous programming to support thousands of connections concurrently.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Client:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Gradually establishes up to &lt;strong&gt;15,000 simultaneous connections&lt;/strong&gt; to the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Measures the &lt;strong&gt;intra-token latency&lt;/strong&gt;—the time between consecutive tokens received from the server. This metric reflects the server’s ability to scale under increasing load.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensures that connections remain stable and records latency for each connection.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Test Workflow:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The server was implemented in &lt;strong&gt;Rust&lt;/strong&gt;, &lt;strong&gt;Python&lt;/strong&gt;, and &lt;strong&gt;JavaScript (Node.js)&lt;/strong&gt; to ensure a fair comparison.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The client progressively increased the number of active connections, starting with a small number and scaling up to 15,000.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Intra-token latency measurements were collected for each implementation to evaluate performance under load.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Results: Rust vs. Python vs. JavaScript (Node.js)
&lt;/h3&gt;

&lt;p&gt;The chart below illustrates the &lt;strong&gt;intra-token latency&lt;/strong&gt; (in milliseconds) as the number of concurrent connections increases:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffso3yojejosxi0ni4su4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffso3yojejosxi0ni4su4.png" alt="Graph Comparing Intra Token Latency" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Key Observations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Rust&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rust exhibited the most stable performance, maintaining a near-linear increase in latency as connections scaled.&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;15,000 connections&lt;/strong&gt;, Rust's intra-token latency reached approximately &lt;strong&gt;75ms&lt;/strong&gt;, only 3x the baseline inter-token latency of 25ms.&lt;/li&gt;
&lt;li&gt;Rust’s efficiency highlights its ability to handle high concurrency without significant degradation.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python's intra-token latency grew exponentially, exceeding &lt;strong&gt;200ms at 15,000 connections&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;This exponential growth demonstrates Python's inherent limitations in managing large-scale concurrency and resource contention.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;JavaScript (Node.js)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js initially performed better than Python, maintaining lower latency up to &lt;strong&gt;7,500 connections&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, its performance began to degrade significantly beyond this point, reaching over &lt;strong&gt;150ms at 15,000 connections&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This result underscores Node.js’s event-driven model, which works well for moderate concurrency but struggles under extreme loads.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why Rust is the Best Choice for an AI Gateway
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Predictable, Scalable Performance:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rust’s ability to maintain &lt;strong&gt;75ms latency at 15,000 connections&lt;/strong&gt; demonstrates its scalability. Its near-linear latency growth makes it ideal for high-concurrency systems.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Concurrency Without Compromise:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rust’s async programming model (e.g., Tokio) efficiently manages thousands of simultaneous connections. Unlike Python, Rust avoids the bottlenecks of the &lt;strong&gt;Global Interpreter Lock (GIL)&lt;/strong&gt; and utilizes system resources optimally.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Resource Efficiency:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rust compiles directly to machine code, ensuring minimal runtime overhead. Its memory safety and zero-cost abstractions allow for predictable and efficient resource management.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Low-Level Control:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rust provides fine-grained control over threading and memory, making it the best choice for performance-critical applications like AI gateways.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why Python and JavaScript Fall Short
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Python:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concurrency Limitations&lt;/strong&gt;: The GIL prevents true multi-threading, causing severe bottlenecks under high load.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Runtime Overhead&lt;/strong&gt;: Python's interpreted nature adds significant latency, making it unsuitable for latency-sensitive applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exponential Growth&lt;/strong&gt;: As connections increase, Python's performance deteriorates rapidly, with latency exceeding acceptable thresholds.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;JavaScript (Node.js):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event-Driven Model&lt;/strong&gt;: Node.js performs well under moderate concurrency but struggles as the number of simultaneous connections grows beyond 7,500.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource Contention&lt;/strong&gt;: While Node.js handles asynchronous I/O well, it lacks the low-level control offered by Rust, leading to degraded performance at scale.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why AI Gateways Must Be Built with Performance in Mind
&lt;/h3&gt;

&lt;p&gt;An AI gateway is more than a simple intermediary. It plays a critical role in ensuring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-Time Responses:&lt;/strong&gt; Users expect tokenized outputs to arrive with minimal delay, making low latency essential.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; AI gateways must handle thousands or tens of thousands of simultaneous connections to accommodate large-scale applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; Inconsistent performance or connection drops can severely impact user experience and application reliability.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rust excels in all these areas, delivering &lt;strong&gt;predictable, stable performance at scale&lt;/strong&gt;, making it the ideal language for building high-performance AI gateways.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Takeaway: Rust is the Future of AI Gateways
&lt;/h3&gt;

&lt;p&gt;Our benchmark results clearly show that while Python and JavaScript (Node.js) have their strengths, they are ill-suited for building performance-critical AI gateways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt; struggles with concurrency and runtime overhead, leading to exponential latency growth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt; performs better but falters under extreme loads, making it unreliable for high-concurrency scenarios.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rust&lt;/strong&gt;, on the other hand, delivers &lt;strong&gt;consistent, scalable performance&lt;/strong&gt; with low latency, even at &lt;strong&gt;15,000 connections&lt;/strong&gt;. By choosing Rust for our AI gateway, we’ve built an infrastructure that can handle the demands of modern AI applications with ease.&lt;/p&gt;

&lt;p&gt;If you’re building an AI gateway or any performance-critical infrastructure, &lt;strong&gt;Rust isn’t just an option—it’s the solution&lt;/strong&gt;. When every millisecond matters, Rust is the language that ensures you meet the challenge head-on.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>ai</category>
      <category>llm</category>
      <category>api</category>
    </item>
    <item>
      <title>Introduction to AI Gateway</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Tue, 10 Dec 2024 17:04:23 +0000</pubDate>
      <link>https://forem.com/langdb/introduction-to-ai-gateway-4kpc</link>
      <guid>https://forem.com/langdb/introduction-to-ai-gateway-4kpc</guid>
      <description>&lt;h3&gt;
  
  
  Rise Of LLMs
&lt;/h3&gt;

&lt;p&gt;In the ever-evolving landscape of technology, few innovations have created waves as transformative as artificial intelligence (AI).&lt;/p&gt;

&lt;p&gt;The rise of AI—fueled by large language models (LLMs)—is reshaping how we think about software, automation, and the user experience. Much like the pivotal shifts brought by mobile computing, cloud infrastructure, and microservices architecture, AI represents a foundational shift in how we design and deliver technology.&lt;/p&gt;

&lt;p&gt;As we embrace this new era of AI, large language models are not just reshaping what’s possible—they’re redefining how we approach technology itself. However, this transformation is only as strong as the underlying frameworks that support it. APIs, as the silent workhorses of modern software, serve as the crucial bridge connecting AI’s potential with real-world applications, ensuring its seamless integration into the fabric of our digital ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is an AI Gateway
&lt;/h3&gt;

&lt;p&gt;An AI Gateway is a middleware platform that simplifies the integration, management, and scaling of artificial intelligence (AI) models and services within an organization’s IT infrastructure. It serves as a critical bridge between AI systems—such as large language models (LLMs)—and the applications or services that consume them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwfnb18p5cznavshhvbc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwfnb18p5cznavshhvbc.png" alt="Workflow with LangDB" width="800" height="446"&gt;&lt;/a&gt;&lt;br&gt;
LangDB’s AI Gateway provides a simplified way to connect with multiple Large Language Models (LLMs) using a single line of code. It’s designed to help developers integrate and manage LLMs efficiently while keeping operations cost-effective.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features of LangDB's AI Gateway
&lt;/h3&gt;

&lt;p&gt;LangDB’s AI Gateway provides developers with a practical, streamlined solution for integrating and managing LLMs. Here’s how it stands out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cost Management: Gain control over LLM usage by tracking and optimizing spending, ensuring cost-effective operations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic Routing: Automatically route requests to the most suitable LLM based on performance, cost, or availability, optimizing results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scalability: Seamlessly scale your AI integrations across projects and environments without added complexity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Seamless Integration: Connect with multiple AI providers using a single line of code, reducing development overhead and increasing productivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Future-Ready: Stay adaptable as new LLMs emerge, ensuring your workflows remain at the cutting edge of AI technology.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Built with developers in mind, LangDB’s AI Gateway empowers you to integrate multiple AI models using just a single line of code. Whether you’re scaling enterprise applications or experimenting with new AI tools, LangDB ensures your workflows are efficient, cost-effective, and future-ready.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;As AI adoption grows, LangDB’s AI Gateway simplifies the process, helping developers focus on building smarter, faster applications without operational overhead. By offering seamless integration, cost optimization, and scalable solutions, it reduces complexity and empowers developers to focus on innovation and delivering impactful results.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>langchain</category>
      <category>openai</category>
    </item>
    <item>
      <title>Exploring Different Chunking Strategies and Working with Unstructured Data</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Fri, 23 Aug 2024 04:13:32 +0000</pubDate>
      <link>https://forem.com/langdb/exploring-different-chunking-strategies-and-working-with-unstructured-data-966</link>
      <guid>https://forem.com/langdb/exploring-different-chunking-strategies-and-working-with-unstructured-data-966</guid>
      <description>&lt;p&gt;LangDB provides a powerful arsenal of functions for developers to deal with unstructured data. These functions are designed to streamline common tasks in data extraction, and text chunking. Let's dive into some of the key functions and see how they can make your life easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  load
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;load&lt;/code&gt; function converts any webpage/file into bytes. These bytes can be used to extract text or layout from the file/webpage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'s3://sample-onlineboutique-codefiles/onlineboutique-codefiles/just-deserts-spring-obooko-small.pdf'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;&lt;th&gt;content&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;[37,80,68,70,45,49,46,54,10,37,-30,-29,-49,-45,10,53,32,48,32,111,98,106,10,60,60,10,47,66,77,32,47,78,111,114,109,97,108,10,47,99,97,32,49,10,62,62,10,101,110,100,111,98,106,10,56,32,48,32,111,98,106,10,60,60,10,47,70,105,108,116,101,114,32,47,70,108,97,116,101,68,101,99,111,100,101,10,47,76,101,110,103,116,104,32,50,57,54,10,47,78,32,51,10,62,62,10,115,116,114,101,97,109,10,120,-100,125,-112,-67,74,-61,96,20,-122,31,107,65,20,-59,65,-121,14,14,25,28,92,-44,-2,104,127,-64,-91,-83,88,92,91,-123,86,-89,52,77,-117,-40,-97,-112,-90,-24,5,-24,-26,-32,-22,38,46,-34,-128,-24,101,40,8,14,-30,-32,37,-120,-96,-77,111,26,36,5,-87,-25,-16,-26,123,120,-13,-110,47,-25,64,36,-122,42,26,-121,78,-41,115,-53,-91,-126,81,-83,29,24,83,-17,76,-88,-121,101,90,125,-121,-15,-91,-44,-9,75,-112,125,94,-3,39,55,-82,-90,27,118,-33,-46,-7,33,121,-82,46,-41,39,27,-30,-59,86,-64,-89,62,-41,3,-66,-16,-7,-60,115,60,-15,-75,-49,-18,94,-71,40,-66,19,-81,-76,70,-72,62,10]&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
  

&lt;h1&gt;
  
  
  extract_text
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;extract_text()&lt;/code&gt; function extracts text from various file types, with specific options available for PDF files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parameters
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Optional&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Possible Values&lt;/th&gt;
&lt;th&gt;Sample Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;path&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;The file path to extract text from&lt;/td&gt;
&lt;td&gt;Any valid  URL&lt;/td&gt;
&lt;td&gt;&lt;code&gt;'https://example.com'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;type&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Type of file&lt;/td&gt;
&lt;td&gt;PDF, Markdown, Text, HTML&lt;/td&gt;
&lt;td&gt;&lt;code&gt;'pdf'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;page_rage&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Array(Int)&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Extra parameter for PDF file type for the range of page numbers&lt;/td&gt;
&lt;td&gt;Array of Start and Ending page numbers&lt;/td&gt;
&lt;td&gt;[1, 10]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;per_page&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bool&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Extra parameter for PDF file type to chunk per Page&lt;/td&gt;
&lt;td&gt;true, false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Usage with &lt;code&gt;load&lt;/code&gt; function
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;extract_text&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="k"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'s3://sample-onlineboutique-codefiles/onlineboutique-codefiles/just-deserts-spring-obooko-small.pdf'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'pdf'&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;per_page&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;content&lt;/th&gt;
&lt;th&gt;metadata&lt;/th&gt;
&lt;th&gt;page_no&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;
&lt;br&gt;
JUST DESERTS&lt;br&gt;
Aniela Spring&lt;br&gt;
© Copyright Aniela Spring 2024&lt;br&gt;
This is an authorised free edition from &lt;a href="http://www.obooko.com" rel="noopener noreferrer"&gt;www.obooko.com&lt;/a&gt;&lt;br&gt;
Although you do not have to pay for this book, the author’s intellectual property&lt;br&gt;
rights remain fully protected by international Copyright laws. You are licensed to&lt;br&gt;
use this digital copy strictly for your personal enjoyment only: it must not be&lt;br&gt;
redistributed commercially or offered for sale in any form. If you paid for this free&lt;br&gt;
edition, or to gain access to it, we suggest you demand an immediate refund and&lt;br&gt;
report the transaction to the author and Obooko.&lt;br&gt;
All characters are fictitious and any resemblance to real persons, living or dead,&lt;br&gt;
is utterly coincidental.&lt;br&gt;
1&lt;/td&gt;
&lt;td&gt;{"total_pages":2,"page_range":"(0, 2)"}&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These all functions are best suited for raw text. However, if you want to get the layout information from a document, LangDB has support for it too.&lt;/p&gt;
&lt;h2&gt;
  
  
  extract_layout
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;extract_layout&lt;/code&gt; function enables structured data extraction with layout information from a document.&lt;/p&gt;
&lt;h3&gt;
  
  
  Parameters
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Optional&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Possible Values&lt;/th&gt;
&lt;th&gt;Sample Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;path&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;The file path to extract text from&lt;/td&gt;
&lt;td&gt;Any valid file URL&lt;/td&gt;
&lt;td&gt;'&lt;a href="https://example.pdf" rel="noopener noreferrer"&gt;https://example.pdf&lt;/a&gt;'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;type&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Type of file&lt;/td&gt;
&lt;td&gt;Raw, PDF, Image&lt;/td&gt;
&lt;td&gt;'pdf'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;page_range&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Array(Int)&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Extra parameter for PDF file type for the range of page numbers&lt;/td&gt;
&lt;td&gt;Array of Start and Ending page numbers&lt;/td&gt;
&lt;td&gt;[1, 10]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;parallelism&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Int&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Extra parameter for PDF file type to process pages parallelly&lt;/td&gt;
&lt;td&gt;2, 4, 5&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Extracting Layout information from a PDF
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;extract_layout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'s3://sample-onlineboutique-codefiles/onlineboutique-codefiles/just-deserts-spring-obooko-small.pdf'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'pdf'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;page&lt;/th&gt;
&lt;th&gt;block_idx&lt;/th&gt;
&lt;th&gt;block_id&lt;/th&gt;
&lt;th&gt;block_type&lt;/th&gt;
&lt;th&gt;row_id&lt;/th&gt;
&lt;th&gt;col_id&lt;/th&gt;
&lt;th&gt;text&lt;/th&gt;
&lt;th&gt;confidence&lt;/th&gt;
&lt;th&gt;entity_types&lt;/th&gt;
&lt;th&gt;relationships&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;c7261e9c-be58-4776-a1de-70adf6e4e6e6&lt;/td&gt;
&lt;td&gt;PAGE&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[["CHILD",["23112b0d-4062-424d-bbb3-4f4aa82f4d80","3e3c5562-b018-4f75-85d9-6e7771489ba0","f08a9210-eedb-4150-99e2-a5d22b26e029","f3087bee-7680-4024-aeff-60ab0bdc1dac"]]]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;23112b0d-4062-424d-bbb3-4f4aa82f4d80&lt;/td&gt;
&lt;td&gt;LINE&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Don't forget about your past, because it never forgets about you.&lt;/td&gt;
&lt;td&gt;99.88849&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[["CHILD",["102e10d5-fd45-46ee-9890-b70279c6e532","af6bad3a-34fc-462e-9033-c1af2bd5aa1a","aab2849a-4a4b-499c-a16f-43c55fb5dffd","78ef1f76-d8a5-413f-be87-cff88194b7e1","9f41e657-f307-487f-872e-569272305ad4","01ae2b2a-755f-4ef9-9ddc-24eaefbaabd4","7484031d-5259-48ad-a3c7-bbcb862d34f0","783ddab6-47a3-48aa-b56b-adc564daa8cd","d7a69ab3-c601-4d9d-9632-7d4f176b2462","d8f537c7-4c64-4a01-9792-088660b1631d","fb7ad2cb-e72d-4013-8399-fa32d46cb21d"]]]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3e3c5562-b018-4f75-85d9-6e7771489ba0&lt;/td&gt;
&lt;td&gt;LINE&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;JUST DESERTS&lt;/td&gt;
&lt;td&gt;98.635315&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[["CHILD",["5e4fc404-7326-4195-a3d7-343a4dea7a8f","f3efd0b2-0c54-49bc-9867-6830eab05403"]]]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;f08a9210-eedb-4150-99e2-a5d22b26e029&lt;/td&gt;
&lt;td&gt;LINE&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;ANIELA SPRING&lt;/td&gt;
&lt;td&gt;99.87999&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[["CHILD",["f4e95636-470f-45eb-a599-4d3e00f754d6","5e8676d2-f90c-4455-b179-083da72c647e"]]]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;102e10d5-fd45-46ee-9890-b70279c6e532&lt;/td&gt;
&lt;td&gt;WORD&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Don't&lt;/td&gt;
&lt;td&gt;99.96765&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;af6bad3a-34fc-462e-9033-c1af2bd5aa1a&lt;/td&gt;
&lt;td&gt;WORD&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;forget&lt;/td&gt;
&lt;td&gt;99.908676&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;aab2849a-4a4b-499c-a16f-43c55fb5dffd&lt;/td&gt;
&lt;td&gt;WORD&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;about&lt;/td&gt;
&lt;td&gt;99.9353&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;78ef1f76-d8a5-413f-be87-cff88194b7e1&lt;/td&gt;
&lt;td&gt;WORD&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;your&lt;/td&gt;
&lt;td&gt;99.92315&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;9f41e657-f307-487f-872e-569272305ad4&lt;/td&gt;
&lt;td&gt;WORD&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;past,&lt;/td&gt;
&lt;td&gt;99.73978&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;01ae2b2a-755f-4ef9-9ddc-24eaefbaabd4&lt;/td&gt;
&lt;td&gt;WORD&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;because&lt;/td&gt;
&lt;td&gt;99.9515&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Extracting Layout information from an Image
&lt;/h2&gt;

&lt;p&gt;Similarly, you can extract layout information from an image through the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;extract_layout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'https://langdb-sample-data.s3.ap-southeast-1.amazonaws.com/Screenshot+from+2024-08-09+09-49-18.png'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'image'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  chunk
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;chunk&lt;/code&gt; function breaks down large texts into smaller, manageable pieces. This is particularly useful for processing long documents, especially when working with models that have input size limitations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parameters
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Optional&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Possible Values&lt;/th&gt;
&lt;th&gt;Sample Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;raw_text&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;The raw text which needs to be chuncked&lt;/td&gt;
&lt;td&gt;Any String&lt;/td&gt;
&lt;td&gt;'In a quaint village...'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;type&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Unit of chunking&lt;/td&gt;
&lt;td&gt;Char, Word, Sentence, Paragraph&lt;/td&gt;
&lt;td&gt;'Char'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;chunk_size&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Int&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Number of units to be present in a Chunk&lt;/td&gt;
&lt;td&gt;Any non-negative integer&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;overlap&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Int&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Number of units to overlap between consecutive chunks&lt;/td&gt;
&lt;td&gt;Any non-negative integer&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;trim&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bool&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Whether to trim whitespace from the start and end of each chunk&lt;/td&gt;
&lt;td&gt;true, false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Chunking Raw text into Char with Chunk Size
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Char'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;trim&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;chunk_size&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;text&lt;/th&gt;
&lt;th&gt;index&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure.&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before.&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen.&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty.&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Chunking Raw text into Word with Chunk Size and Overlap
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Word'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;chunk_size&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;overlap&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;text&lt;/th&gt;
&lt;th&gt;index&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;In a quaint village nestled in the heart of the countryside there lived a young girl named Lily She was known throughout the village for her vibrant imagination and her&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;known throughout the village for her vibrant imagination and her love for adventure Every day Lily would set out to explore the lush forests and rolling hills that surrounded her&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;explore the lush forests and rolling hills that surrounded her home always eager to discover something new and exciting

&lt;p&gt;One particularly sunny morning Lily decided to venture deeper into the&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;particularly sunny morning Lily decided to venture deeper into the woods than she ever had before As she walked she stumbled upon a hidden grove filled with the most beautiful&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen The colors were so vivid and the petals so delicate that Lily couldnt help but&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;and the petals so delicate that Lily couldnt help but marvel at their beauty She spent hours in the grove carefully examining each flower and breathing in their sweet fragrance&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Chunking Raw Text into Sentences
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Sentence'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;text&lt;/th&gt;
&lt;th&gt;index&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;She was known throughout the village for her vibrant imagination and her love for adventure&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Chunking Raw Text into Paragraphs
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Paragraph'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;text&lt;/th&gt;
&lt;th&gt;index&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h1&gt;
  
  
  Combining functions
&lt;/h1&gt;

&lt;p&gt;We have seen how these functions behave individually, but the real power of these functions and LangDB lies within combining. Let's take an example of a job description pdf.&lt;/p&gt;

&lt;p&gt;Firstly, we will use &lt;code&gt;load&lt;/code&gt; to convert the file into bytes and then &lt;code&gt;extract_text&lt;/code&gt; to get all the raw text from it.&lt;br&gt;
After that, we will Chunk by &lt;code&gt;Char&lt;/code&gt; with a &lt;code&gt;chunk_size&lt;/code&gt; of 2000.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;extract_text&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;
            &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="k"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://www.stjohneyehospital.org/wp-content/uploads/2024/05/Job-Description-Accountant.pdf'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'pdf'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;chunk_size&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Char'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;trim&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;text&lt;/th&gt;
&lt;th&gt;index&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ST. JOHN EYE HOSPITAL – JERUSALEM&lt;br&gt;
JOB DESCRIPTION&lt;br&gt;
Title Accountant&lt;br&gt;
Department Finance&lt;br&gt;
Section&lt;br&gt;
Reports to Director of Finance&lt;br&gt;
Hours 40 hrs per week (inc of lunch breaks)&lt;br&gt;
Date February 24&lt;br&gt;
formulated/updated&lt;br&gt;
General Statement of Duties: To play a major role in controlling the costing system of purchases and&lt;br&gt;
payroll by supporting the existing accountants and providing reports as instructed by the Director of Finance.&lt;br&gt;
Main Responsibilities:

&lt;ol&gt;
&lt;li&gt;To act as a substitute for the senior/payroll accountant during her absence.&lt;/li&gt;
&lt;li&gt;Act as the Projects’ accountant and point of contact by providing reports and supporting documents
for projects and any other assistance as needed.&lt;/li&gt;
&lt;li&gt;Act as the Cafeteria’s accountant which includes recording of expenses and income, produce reports for
management, as well as reporting to the tax authority.&lt;/li&gt;
&lt;li&gt;Responsible for examining, recording, and summarizing the organization’s West Bank costs, mainly
payroll and purchases. The Accountant records and classifies expenditures to create financial statements
for senior management.&lt;/li&gt;
&lt;li&gt;Ensure that all costs are identified and recorded accurately.&lt;/li&gt;
&lt;li&gt;Maintaining accurate costing records in relation to labour and supplies.&lt;/li&gt;
&lt;li&gt;Process accounting transactions using the existing accounting software.&lt;/li&gt;
&lt;li&gt;Assist in the preparation of the monthly local management accounts and comparing it to budget, and
report on any variance to DOF and other heads of departments.&lt;/li&gt;
&lt;li&gt;Process Palestinian payroll transactions using accounting and payroll systems and assist with the Israeli
payroll system when needed (and ensure that the payroll taxes and national insurance are paid to the
regulatory bodies on timely basis).&lt;/li&gt;
&lt;li&gt;Revision of purchases recorded at the pharmacy system.&lt;/li&gt;
&lt;li&gt;Monitor and coordinate payments for West Bank Suppliers&lt;/li&gt;
&lt;li&gt;Any other duties as assigned by the Director of Finance.
General Responsibilities:&lt;/li&gt;
&lt;/ol&gt;
&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1. All staff are expected to report for work on time and fulfil their hours of duty, from time to time some
flexibility may be required in order to meet the needs of the job and this may be outside regular hours of
work.
&lt;li&gt;All staff are expected to promote and contribute to a cooperative and productive work environment. Staff
are also expected to show respect and consideration to their colleagues and all patients and visitors to the
hospital.&lt;/li&gt;
&lt;li&gt;All staff are expected to follow the dress code for their area of work. All uniforms as required by different
work areas should be worn at all times. Staff who do not have a uniform are expected to wear appropriate,
respectful, modest business dress. Jeans are not considered appropriate attire.&lt;/li&gt;
&lt;li&gt;The hospital is a no smoking hospital and smoking is only permitted in the designated smoking areas and
only during official break periods.&lt;/li&gt;
&lt;li&gt;All staff will abide by confidentiality rules and will not disclose any information about patients, the staff or
the workings of the hospital, except in certain circumstances where express permission is given as per the
Confidentiality Policy.&lt;/li&gt;
&lt;li&gt;All staff are expected to comply at all times with the requirements of Health and Safety regulations and to
take responsibility for the health and safety and welfare of others in the working environment ensuring that
agreed safety procedures are carried out to maintain a safe environment.&lt;/li&gt;
&lt;li&gt;The Hospital has a Control of Visits in the Hospital and Security of Workers policy in order to help protect
patients, visitors and staff and to safeguard their property. All employees have a responsibility to ensure
that those persons using the Hospital and its service are as secure as possible.&lt;/li&gt;
&lt;li&gt;The Hospital is committed to equality and all staff are expected to treat colleagues, patients and visitors to
the Hospital with dignity and respect, regardless of their ethnic background, religion, race, gender, age or&lt;/li&gt;
&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;sexual orientation.
&lt;li&gt;All staff are expected to familiarise themselves with the requirements of the Hospitals policies and
procedures for staff and also their specific area of work.&lt;/li&gt;
&lt;li&gt;All appointments within the Hospital are subject to pre-employment health screening.&lt;/li&gt;
&lt;li&gt;All staff are responsible for ensuring that all risks of cross infection to patients are minimised and that all
policies, procedures and guidance relating to infection control practice are adhered to.&lt;/li&gt;
&lt;li&gt;All staff are responsible, where relevant, for ensuring that all equipment used by patients is
clean/decontaminated as instructed by manufacturers and in line with the infection control/guidelines
protocol and policy.&lt;/li&gt;
&lt;li&gt;The job description gives a general outline of the duties of the position and is not intended to be an
inflexible or finite list of tasks. It may be varied, from time to time, after consultation with the member of
staff.&lt;/li&gt;
&lt;li&gt;Any other duties as designated by your manager and which are commensurate with the grade.
Essential requirements for the post:
Bachelor’s degree in accounting.
At least one year experience in the accounting field mainly in the payable’s sections.
At least one year experience in processing payroll. Knowledge and experience of the Israeli &amp;amp; Palestinian Payroll
systems is required.
Previous experience in projects is a plus.
Very Good in English and Hebrew languages.
Computer literate especially excel spread sheets.
Good eye for details.
Methodical and organised.
Ability to work under pressure.
Ability to meet deadlines.
Ability to lead &amp;amp; contribute to team work as necessary.
Name ______________________________________________ Date ________________________
Signed ______________________________________&lt;/li&gt;
&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;p&gt;By leveraging functions like &lt;code&gt;load&lt;/code&gt;, &lt;code&gt;extract_text&lt;/code&gt;, &lt;code&gt;extract_layout&lt;/code&gt; and &lt;code&gt;chunk&lt;/code&gt;, LangDB equips developers with a powerful toolkit for overcoming unstructured data challenges. Whether you're dealing with disorganized text, intricate document layouts, or vast amounts of data, these functions provide the versatility and efficiency needed to convert raw information into structured, actionable insights. LangDB not only simplifies the complexity of data extraction and processing but also enhances the overall productivity of your development workflow.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>llm</category>
      <category>data</category>
    </item>
    <item>
      <title>Unlocking the Power of Text-to-SQL with LangDB</title>
      <dc:creator>Sayantan Bera</dc:creator>
      <pubDate>Thu, 22 Aug 2024 17:28:55 +0000</pubDate>
      <link>https://forem.com/langdb/unlocking-the-power-of-text-to-sql-with-langdb-489h</link>
      <guid>https://forem.com/langdb/unlocking-the-power-of-text-to-sql-with-langdb-489h</guid>
      <description>&lt;p&gt;The Text-to-SQL model in LangDB transforms natural language queries into precise Clickhouse SQL commands, streamlining data extraction from your databases. By understanding user intent and targeting specific tables, it delivers highly accurate results, bridging the gap between natural language and complex SQL operations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbHFrMTcyZWVrNTk1aHplOTBlczRzZ2lzamFvcmVvY3Y3NHJoYWo3YiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/xAF6NJH34Fr6JDOaji/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbHFrMTcyZWVrNTk1aHplOTBlczRzZ2lzamFvcmVvY3Y3NHJoYWo3YiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/xAF6NJH34Fr6JDOaji/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools required for Text-to-SQL Model
&lt;/h2&gt;

&lt;p&gt;The model relies on several built-in tools provided by LangDB:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;langdb_raw_query&lt;/code&gt;: Executes SQL queries directly on the database.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;langdb_validate_query&lt;/code&gt;: Ensures the generated SQL query is correct before execution.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;list_tables&lt;/code&gt;: Retrieves available table names within the database.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;describe_tables&lt;/code&gt;: Provides detailed information about specific tables.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tools work together to simplify natural language to SQL translation and ensure query accuracy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Prompt Creation for Query Agent
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE PROMPT query_prompt(
    system "You are an advanced query agent specializing in Clickhouse SQL. Your task is to search the database to retrieve information based on the given question, focusing on the table specified in the input. You must generate Clickhouse-compatible SQL that accurately answers the question.

    Follow these steps for EVERY query:

    Step 1: Get Database Schema
    Action: list_tables tool
    Action Input: all
    Observation: [Output from list_tables tool list all tables in the specified schema]


    Step 2: Analyze Tables and Focus on pick tables to query
    Thought: Based on the question, and the available tables, I will focus on the required tables and identify any potential relationships with other tables if needed.
    Related Tables (if any): [Names of potentially related tables from the schema]
    Reason: [Explanation for why the specified table is appropriate and how any related tables might be useful]

    Step 3: Describe Table
    Action: describe_tables tool
    Action Input: [Related Table names from Step 2]
    Observation: [Output from list_tables tool list all tables in the specified schema]


    Step 4: Generate and Execute Clickhouse SQL Query
    Thought: I will now generate a Clickhouse SQL query that accurately answers the question, focusing on the specified table. Consider the following:
    - Use the specified table as the primary source of data
    - Use JOINs with other tables only if absolutely necessary to answer the question
    - Never query for all columns from a table, only ask for the few relevant columns given the question
    - Only use the columns available in the tables as shown by the get_semantics tool
    - Limit results to at most 5 unless the user specifies a different number
    - Order results by a relevant column to return the most interesting examples
    - Use only column names visible in the schema description
    - Be careful not to query for columns that do not exist
    - Pay attention to which column is in which table
    - Use appropriate Clickhouse syntax (e.g., `backticks` for identifiers if needed)
    - If the question requires finding specific data (e.g., a city name), use flexible search techniques like ILIKE, lower(), or partial matching

    Step 4: Validate the SQL Query
    Action: langdb_validate_query tool
    Action Input: [Your generated ClickHouse SQL query]
    Observation: [true or false]

    Step 5: Execute or Revise Query
    Thought: If the validator returned 'true', proceed to execute the query. If 'false', revise the query and go back to Step 3.
    Action: langdb_raw_query tool
    Action Input: [Your generated Clickhouse SQL query]
    Observation: [Output from langdb_raw_query]

    Always provide your final response in this EXACT format:

    Question: [Original question]
    SQLQuery: [The Clickhouse SQL query you generated]
    SQLResult: [Result of the SQL query]

    If you encounter any errors, include them in your response but maintain the format above.

    Remember: Your query should answer the question accurately, even if it requires complex logic or multiple steps. Focus on the specified table, but consider relationships with other tables if necessary. Use flexible search techniques when looking for specific data. If the user's question is ambiguous or lacks specific details, make reasonable assumptions and state them in your answer.",

    human "{{input}}"
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 2: Model Creation
&lt;/h2&gt;

&lt;p&gt;Now, we can create the models that can leverage the tools that were created earlier.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE MODEL text_to_sql(
    input
) USING open_ai_provider(model_name = 'gpt-4o')
PROMPT query_prompt
TOOLS (
    list_tables COMMENT 'Tool to get the tables from the database',
    langdb_raw_query COMMENT 'Tool to execute SQL query over the database',
    describe_tables COMMENT 'Tool to describe a table in the database',
    langdb_validate_query COMMENT 'Tool to validate generated SQL query'
)
SETTINGS retries = 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And just like that, we’re done! Building this Text-to-SQL model with LangDB was this straightforward.&lt;/p&gt;

&lt;p&gt;Give it a shot yourself &lt;a href="https://app.langdb.ai/share/apps/7f5b857f-5520-4e9a-9027-916c7cfba7d2" rel="noopener noreferrer"&gt;Text-to-SQL Notebook&lt;/a&gt; — LangDB makes it so easy for you.&lt;/p&gt;

&lt;p&gt;Join our Slack community for more discussions and support: &lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://langdbcommunity.slack.com/join/shared_invite/zt-2haf5kj6a-d7NX6TFJUPX45w~Ag4dzlg" rel="noopener noreferrer"&gt;
      langdbcommunity.slack.com
    &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>datascience</category>
      <category>sql</category>
      <category>tutorial</category>
      <category>langdb</category>
    </item>
    <item>
      <title>Running Text-To-SQL on MongoDB: Working with Postgres, MySQL, MongoDB and Others</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Wed, 07 Aug 2024 13:42:52 +0000</pubDate>
      <link>https://forem.com/langdb/running-text-to-sql-on-mongodb-working-with-postgres-mysql-mongodb-and-others-2cgg</link>
      <guid>https://forem.com/langdb/running-text-to-sql-on-mongodb-working-with-postgres-mysql-mongodb-and-others-2cgg</guid>
      <description>&lt;p&gt;When working with LangDB, one question that developers ask how langdb integrates with their existing data infrastructure. Fortunately, LangDB offers seamless connectivity to your pre-existing databases, allowing you to leverage your data without significant modifications. &lt;/p&gt;

&lt;h2&gt;
  
  
  Database Integrations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Table Engines
&lt;/h3&gt;

&lt;p&gt;LangDB, built on top of Clickhouse, provides native support for integrating with a wide range of databases. This means you can use the Integration Engines of Clickhouse to continue using your existing databases while benefiting from LangDB's SQL arsenal.&lt;/p&gt;

&lt;p&gt;Here are a few examples of how you can connect to some popular databases. You can find more about them here: &lt;a href="https://clickhouse.com/docs/en/engines/table-engines#integration-engines" rel="noopener noreferrer"&gt;Table Engines&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE: Original article can be found at &lt;a href="https://app.langdb.ai/share/apps/4250cb28-5e2b-421f-9711-0f334452aef5" rel="noopener noreferrer"&gt;https://app.langdb.ai/share/apps/4250cb28-5e2b-421f-9711-0f334452aef5&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  PostgreSQL
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;col_name1&lt;/span&gt; &lt;span class="n"&gt;type1&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;col_name2&lt;/span&gt; &lt;span class="n"&gt;type2&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ENGINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PostgreSQL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  MySQL
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt; 
&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;col_name1&lt;/span&gt; &lt;span class="n"&gt;type1&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;col_name2&lt;/span&gt; &lt;span class="n"&gt;type2&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ENGINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MySQL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  MongoDB
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt; 
&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;col_name1&lt;/span&gt; &lt;span class="n"&gt;type1&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;col_name2&lt;/span&gt; &lt;span class="n"&gt;type2&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ENGINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MongoDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="p"&gt;[,&lt;/span&gt; &lt;span class="s1"&gt;'ssl=true&amp;amp;tls=true&amp;amp;tlsAllowInvalidCertificates=true&amp;amp;connectTimeoutMS=30000&amp;amp;socketTimeoutMS=60000&amp;amp;authSource=admin'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Table Functions
&lt;/h3&gt;

&lt;p&gt;Apart from the table engines, you can also query your existing databases directly using &lt;code&gt;table functions&lt;/code&gt; There are Postgresql, MongoDB, MySQL, and many other table functions.&lt;br&gt;
You can read more about them here: &lt;a href="https://clickhouse.com/docs/en/sql-reference/table-functions" rel="noopener noreferrer"&gt;Table Functions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's take the example of MongoDB. On MongoDB Atlas, I will use &lt;a href="https://www.mongodb.com/docs/atlas/sample-data/sample-analytics/" rel="noopener noreferrer"&gt;Sample Analytics Dataset&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;sample_analytics&lt;/code&gt; database contains three collections for a typical financial services application. It has customers, accounts, and transactions. &lt;/p&gt;

&lt;p&gt;We will focus on &lt;code&gt;accounts&lt;/code&gt;, but feel free to play around. The &lt;code&gt;accounts&lt;/code&gt; collection contains the details of the users. &lt;/p&gt;

&lt;p&gt;We can use the &lt;code&gt;mongodb&lt;/code&gt; table function to query the collection quickly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;mongodb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'host:port'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'sample_analytics'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'customers'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="s1"&gt;'_id String, 
     username String, 
     name String, 
     address String, 
     birthdate DateTime, 
     email String, 
     accounts Array(Int32)'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'connectTimeoutMS=10000&amp;amp;ssl=true&amp;amp;authSource=admin'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;_id&lt;/th&gt;
&lt;th&gt;username&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;address&lt;/th&gt;
&lt;th&gt;birthdate&lt;/th&gt;
&lt;th&gt;email&lt;/th&gt;
&lt;th&gt;accounts&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162a69&lt;/td&gt;
&lt;td&gt;valenciajennifer&lt;/td&gt;
&lt;td&gt;Lindsay Cowan&lt;/td&gt;
&lt;td&gt;Unit 1047 Box 4089
DPO AA 57348&lt;/td&gt;
&lt;td&gt;1994-02-19 23:46:27&lt;/td&gt;
&lt;td&gt;cooperalexis@hotmail.com&lt;/td&gt;
&lt;td&gt;[116508]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162b29&lt;/td&gt;
&lt;td&gt;crodriguez&lt;/td&gt;
&lt;td&gt;Charles Jones&lt;/td&gt;
&lt;td&gt;183 Young Mountain
Rossmouth, DC 11579&lt;/td&gt;
&lt;td&gt;1974-01-24 12:12:53&lt;/td&gt;
&lt;td&gt;vancejohnny@hotmail.com&lt;/td&gt;
&lt;td&gt;[467666]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162a76&lt;/td&gt;
&lt;td&gt;portermichael&lt;/td&gt;
&lt;td&gt;Lauren Clark&lt;/td&gt;
&lt;td&gt;1579 Young Trail
Jessechester, OH 88328&lt;/td&gt;
&lt;td&gt;1980-10-28 16:25:59&lt;/td&gt;
&lt;td&gt;briannafrost@yahoo.com&lt;/td&gt;
&lt;td&gt;[883283,980867,164836,200611,528224,931483]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162a72&lt;/td&gt;
&lt;td&gt;wesley20&lt;/td&gt;
&lt;td&gt;James Sanchez&lt;/td&gt;
&lt;td&gt;8681 Karen Roads Apt. 096
Lowehaven, IA 19798&lt;/td&gt;
&lt;td&gt;1973-01-13 16:17:26&lt;/td&gt;
&lt;td&gt;josephmacias@hotmail.com&lt;/td&gt;
&lt;td&gt;[987709]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162bf4&lt;/td&gt;
&lt;td&gt;skinnercraig&lt;/td&gt;
&lt;td&gt;Ashley Lindsey&lt;/td&gt;
&lt;td&gt;Unit 6691 Box 1189
DPO AP 53029&lt;/td&gt;
&lt;td&gt;1994-06-16 07:38:48&lt;/td&gt;
&lt;td&gt;robertwalker@gmail.com&lt;/td&gt;
&lt;td&gt;[375655,892096,401997,253554,890055,959435]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;However, to use LangDB's collection of tools like Text-to-SQL and Embeddings, it is better to use the table engines. You can do something like this for the above query to get read-only access to the remote MongoDB collection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="n"&gt;customers_mongodb&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;
     &lt;span class="n"&gt;_id&lt;/span&gt; &lt;span class="nv"&gt;"String"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="nv"&gt;"String"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nv"&gt;"String"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="nv"&gt;"String"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="n"&gt;birthdate&lt;/span&gt; &lt;span class="nb"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nv"&gt;"String"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="n"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Int32"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ENGINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MongoDB&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'host:port'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'sample_analytics'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'customers'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'ssl=true&amp;amp;tls=true&amp;amp;tlsAllowInvalidCertificates=true&amp;amp;connectTimeoutMS=30000&amp;amp;socketTimeoutMS=60000&amp;amp;authSource=admin'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers_mongodb&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;_id&lt;/th&gt;
&lt;th&gt;username&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;address&lt;/th&gt;
&lt;th&gt;birthdate&lt;/th&gt;
&lt;th&gt;email&lt;/th&gt;
&lt;th&gt;accounts&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162a69&lt;/td&gt;
&lt;td&gt;valenciajennifer&lt;/td&gt;
&lt;td&gt;Lindsay Cowan&lt;/td&gt;
&lt;td&gt;Unit 1047 Box 4089
DPO AA 57348&lt;/td&gt;
&lt;td&gt;1994-02-19 23:46:27&lt;/td&gt;
&lt;td&gt;cooperalexis@hotmail.com&lt;/td&gt;
&lt;td&gt;[116508]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162b29&lt;/td&gt;
&lt;td&gt;crodriguez&lt;/td&gt;
&lt;td&gt;Charles Jones&lt;/td&gt;
&lt;td&gt;183 Young Mountain
Rossmouth, DC 11579&lt;/td&gt;
&lt;td&gt;1974-01-24 12:12:53&lt;/td&gt;
&lt;td&gt;vancejohnny@hotmail.com&lt;/td&gt;
&lt;td&gt;[467666]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162a76&lt;/td&gt;
&lt;td&gt;portermichael&lt;/td&gt;
&lt;td&gt;Lauren Clark&lt;/td&gt;
&lt;td&gt;1579 Young Trail
Jessechester, OH 88328&lt;/td&gt;
&lt;td&gt;1980-10-28 16:25:59&lt;/td&gt;
&lt;td&gt;briannafrost@yahoo.com&lt;/td&gt;
&lt;td&gt;[883283,980867,164836,200611,528224,931483]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162a72&lt;/td&gt;
&lt;td&gt;wesley20&lt;/td&gt;
&lt;td&gt;James Sanchez&lt;/td&gt;
&lt;td&gt;8681 Karen Roads Apt. 096
Lowehaven, IA 19798&lt;/td&gt;
&lt;td&gt;1973-01-13 16:17:26&lt;/td&gt;
&lt;td&gt;josephmacias@hotmail.com&lt;/td&gt;
&lt;td&gt;[987709]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5ca4bbcea2dd94ee58162bf4&lt;/td&gt;
&lt;td&gt;skinnercraig&lt;/td&gt;
&lt;td&gt;Ashley Lindsey&lt;/td&gt;
&lt;td&gt;Unit 6691 Box 1189
DPO AP 53029&lt;/td&gt;
&lt;td&gt;1994-06-16 07:38:48&lt;/td&gt;
&lt;td&gt;robertwalker@gmail.com&lt;/td&gt;
&lt;td&gt;[375655,892096,401997,253554,890055,959435]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now that we have created a table, we can use a &lt;a href="https://app.langdb.ai/samples/text-to-sql" rel="noopener noreferrer"&gt;&lt;code&gt;Text-To-SQL&lt;/code&gt;&lt;/a&gt; model directly onto the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;text_to_sql&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'How Many accounts are from people who were born in 1994'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question: How many accounts are from people who were born in 1994?
SQLQuery: `SELECT COUNT(*) as account_count FROM customers_mongodb WHERE toYear(birthdate) = 1994`
SQLResult: [{"account_count":"19"}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's verify and run that query for ourselves to confirm it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;account_count&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers_mongodb&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;toYear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;birthdate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1994&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;&lt;th&gt;account_count&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;19&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;LangDB's features like Text-to-SQL and embeddings can streamline your data querying and analysis process, making extracting valuable insights from your databases more accessible. The example we walked through illustrates the simplicity of getting started with LangDB and how it can complement your existing setup.&lt;/p&gt;

&lt;p&gt;As you explore LangDB further, remember that its flexibility and compatibility can significantly enhance your development workflow. &lt;/p&gt;

&lt;p&gt;So, if you're ready to take your database experience to the next level with Gen AI, try LangDB. Its integration capabilities and robust features might become a go-to tool in your development arsenal.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>database</category>
      <category>openai</category>
      <category>ai</category>
    </item>
    <item>
      <title>Building a PDF Chatbot with RAG using SQL</title>
      <dc:creator>Mrunmay </dc:creator>
      <pubDate>Mon, 15 Jul 2024 06:41:04 +0000</pubDate>
      <link>https://forem.com/langdb/building-a-pdf-chatbot-with-rag-using-sql-37b9</link>
      <guid>https://forem.com/langdb/building-a-pdf-chatbot-with-rag-using-sql-37b9</guid>
      <description>&lt;p&gt;In the realm of AI chatbot development, there are many ways to create a PDF chatbot using Retrieval Augmented Generation. There are tools like LangChain and LlamaIndex, which are the popular choice. However, in this post, we’ll be exploring how you can achieve this using SQL.&lt;/p&gt;

&lt;p&gt;Let’s go over the general steps of building a RAG chatbot:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Loading and Extracting PDF&lt;/li&gt;
&lt;li&gt;Generating and Storing Vector Embeddings&lt;/li&gt;
&lt;li&gt;Retrieving relevant information using Vector Search&lt;/li&gt;
&lt;li&gt;Generating and Returning Answer&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why SQL?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;SQL queries are straightforward and efficient, making data manipulation and retrieval easier on large datasets.&lt;/li&gt;
&lt;li&gt;Combining structured and unstructured data is accessible on the go.&lt;/li&gt;
&lt;li&gt;Streamlines the development process by enabling the creation of workflows with minimal code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are a few examples of how easily you can create embeddings, create a prompt for the LLM and finally create a model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Embeddings Model &lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="n"&gt;EMBEDDING&lt;/span&gt; &lt;span class="n"&gt;MODEL&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="n"&gt;generate_embed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="k"&gt;input&lt;/span&gt; &lt;span class="k"&gt;COMMENT&lt;/span&gt; &lt;span class="s1"&gt;'This is the input of the content whose embeddings are created'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="n"&gt;open_ai_provider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;embedding_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'text-embedding-ada-002'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding_format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'float'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dimensions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- Completions Model&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="n"&gt;MODEL&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="k"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;input&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="n"&gt;open_ai_provider&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;PROMPT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;system&lt;/span&gt; &lt;span class="nv"&gt;"You are a helpful assistant. You have been provided with similar tool to search over the SEC fillings. 
                 Your task is also to help users with any queries they might have about the SEC filings. 
                 Go through all the content and then respond."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;human&lt;/span&gt; &lt;span class="nv"&gt;"{{input}}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;TOOLS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;similar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;SETTINGS&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using SQL in this manner provides a robust framework for building a PDF chatbot, leveraging the power of SQL for workflow management.&lt;br&gt;
So, the final execution of the model will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdiqi3p4uwecuef7vzwsa.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdiqi3p4uwecuef7vzwsa.gif" alt="Gif showing how to query a model in LangDB" width="1186" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can follow the full tutorial here: &lt;a href="https://app.langdb.ai/samples/preview?file_name=QA%20on%20PDF%20%26%20RAG%20using%20LangDB" rel="noopener noreferrer"&gt;https://app.langdb.ai/samples/preview?file_name=QA%20on%20PDF%20%26%20RAG%20using%20LangDB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Join our Slack community for more discussions and support: &lt;a href="https://join.slack.com/t/langdbcommunity/shared_invite/zt-2haf5kj6a-d7NX6TFJUPX45w~Ag4dzlg" rel="noopener noreferrer"&gt;https://join.slack.com/t/langdbcommunity/shared_invite/zt-2haf5kj6a-d7NX6TFJUPX45w~Ag4dzlg&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>database</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
