<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fcastrillon on Medium]]></title>
        <description><![CDATA[Stories by Fcastrillon on Medium]]></description>
        <link>https://medium.com/@fcastrillon?source=rss-dc92563779fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eGOQ6PmkvCdWcq_z</url>
            <title>Stories by Fcastrillon on Medium</title>
            <link>https://medium.com/@fcastrillon?source=rss-dc92563779fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 07:58:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fcastrillon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Custom GenAI Analyzer for Spreadsheet Ninjas]]></title>
            <link>https://medium.com/google-cloud/custom-genai-analyzer-for-spreadsheet-ninjas-6c2dc65fd4e5?source=rss-dc92563779fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c2dc65fd4e5</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[google-sheets]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[langchain-agents]]></category>
            <dc:creator><![CDATA[Fcastrillon]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 21:24:03 GMT</pubDate>
            <atom:updated>2025-02-05T15:59:06.652Z</atom:updated>
            <content:encoded><![CDATA[<h3>Customized GenAI Analyzer for Google Sheets</h3><p>As LLMs become more powerful reasoning engines, enterprises want to enable their Spreadsheet Ninjas employees with QnA capabilities. This unfortunately has proven tricky as LLMs often don’t do a great job when doing analytics on-they-fly.</p><p>Some of the more advanced QnA capabilities are available today via public chatbots like Google’s Gemini Assistant or OpenAI’s ChatGPT. However, this does not provide enterprise-wide guardrails or a customized user experience.</p><p>In this article we provide an example on how to create a customizable approach to building your own structured CSV QnA applications that can help your business analysts answer questions like:</p><ul><li>How many rows are in this file?</li><li>Can you provide a count of customers based on the country?</li><li>Can you categorize each row into one of 5 categories based on the customer comments?</li></ul><h3>A Naive Approach: Ask LLMs Directly</h3><h4>Reading the Data</h4><p>In this section we analyze whether we can ask some of these questions directly to an LLM and hopefully be done with it. Let’s get familiar with some of our sample dummy dataset with 100 rows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*e8LTJzq-BTsPuv689loO3g.png" /></figure><p>And here is a snippet on how to read the data directly from the Google Sheets:</p><pre>from googleapiclient.discovery import build<br>from google.oauth2 import service_account<br><br># The path to your downloaded JSON key file<br>SERVICE_ACCOUNT_FILE = &#39;&lt;Service Account File&gt;&#39;<br><br># The scope of access (what you want to do with the Sheets API)<br>SCOPES = [&#39;https://www.googleapis.com/auth/spreadsheets&#39;]<br><br># Authenticate using the service account key<br>creds = service_account.Credentials.from_service_account_file(<br>    SERVICE_ACCOUNT_FILE, scopes=SCOPES)<br><br># Build the Sheets API service<br>service = build(&#39;sheets&#39;, &#39;v4&#39;, credentials=creds)<br><br># Now you can use the &#39;service&#39; object to interact with the Sheets API<br># For example, to read data from a sheet:<br>spreadsheet_id = &#39;&lt;Spreadsheet ID&gt;&#39;  # The ID of your Google Sheet<br>range_name = &#39;Sheet1!A1:Z100&#39;  # The range of cells you want to read<br>result = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=range_name).execute()<br>values = result.get(&#39;values&#39;, [])<br><br>if not values:<br>    print(&#39;No data found.&#39;)<br>else:<br>    for row in values:<br>        print(row)</pre><h4>LLM Analysis</h4><p>Let’s first get the ground truth answers using Pandas before we compare to the LLM analysis:</p><pre>import pandas as pd<br>df = pd.DataFrame(values[1:], columns=values[0])<br><br>print(&quot;number of rows: &quot; + str(len(df)))<br>print(&quot;number of rows where country is US: &quot; + str(len(df[df[&#39;country&#39;].str.contains(&#39;US&#39;)])))<br>print(&quot;number of rows where country is Canada: &quot; + str(len(df[df[&#39;country&#39;].str.contains(&#39;Canada&#39;)])))<br>print(&quot;number of rows where country is Mexico: &quot; + str(len(df[df[&#39;country&#39;].str.contains(&#39;Mexico&#39;)])))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*jbc5Q21_ntKkVO0Ve2wgpg.png" /></figure><p>Now, let’s ask the same questions to an LLM (Gemini 1.5-Pro) directly:</p><pre>from langchain_google_vertexai import ChatVertexAI<br>llm = ChatVertexAI(model=&quot;gemini-1.5-pro-002&quot;)<br><br>llm.invoke(values + &quot;\n how many rows in the file?&quot;).content<br><br>print(llm.invoke(csv_string + &quot;\n how many rows in the file?, please be brief&quot;).content)<br>print(llm.invoke(csv_string + &quot;\n how many rows from the US?, please be brief&quot;).content)<br>print(llm.invoke(csv_string + &quot;\n how many rows from Canada?, please be brief&quot;).content)<br>print(llm.invoke(csv_string + &quot;\n how many rows from Mexico?, please be brief&quot;).content)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*xQXWQYqVjfUXsUyKgLAfCQ.png" /></figure><p>It turns out that LLMs are just not very good at doing analytics on data. They are not specifically good at aggregations or arithmetic functions. For that we turn to an Agentic approach in order to solve these types of questions.</p><h3>Building an Analytics Agent</h3><p>In order to build an agent that can reason we are going to use Langchain ReAct agents alongside a Python-Pandas helper to help us perform analytics. The agent is going to help us:</p><p>(1) understand the question</p><p>(2) send the right query to the analytical engine (i.e. Python-Pandas)</p><p>(3) answer the question in a conversational way.</p><p>An agent works by thinking before answering. It also works by leveraging “Tools” that can help the Agent perform the task. These tools could be your enterprise data, functions or APIs that you can call to get accurate answers.</p><p>Here is an example of how ReAct agents work in action by using Thoughts, Action Inputs, Observations, LLM Models and Tools to get the Final Answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wK0EaPTed0jXMCYronnEw.png" /><figcaption>Example ReAct Agent (Source: “Agents” by Julia Wiesinger, Patrick Marlow and Vladimir Vuskovic)</figcaption></figure><h4>Building Tools</h4><p>In order to answer questions from our sample spreadsheet questions we are going to create three functions which are wrapped inside a LangChain Tool:</p><ol><li><em>csv_summary_statistics</em> <em>Tool</em>: Before answering any questions we want to invoke this tool to get a good sense of what the data looks like</li><li><em>pandas_calculator</em> <em>Tool</em>: This is our main tool that will help us perform reliable calculations on the dataset</li><li><em>generate_column</em> <em>Tool</em>: For some complex tasks we need to create a new column that is generated by the LLM. This can help answer tasks like sentiment analysis or content categorization.</li></ol><p>For more information on the Tools that are being used see <a href="https://github.com/felipecastrillon/FelipesGenAIExplorer/blob/main/csv_analyzer.ipynb">here</a>.</p><h4>Building The Agent Brain with LangChain on Vertex AI</h4><p>For this task, we are going to leverage <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/overview">LangChain on Vertex</a>. This helps to create a runtime deployment for the Agent in a secure cloud environment while still maintaining the flexibility of the Langchain SDK.</p><p>On the code below, note how we are passing the LLM, tools and prompts to the agent without having to specify any additional logic. LangChain and Vertex take care of the rest.</p><pre>from typing import Sequence<br>from langchain_core.language_models import BaseLanguageModel<br>from langchain_core.prompts import BasePromptTemplate<br>from langchain_core.tools import BaseTool<br>from langchain import hub<br>import vertexai<br>from vertexai.preview import reasoning_engines<br><br>vertexai.init(<br>    project=PROJECT,<br>    location=LOCATION,<br>    staging_bucket=&quot;gs://&quot; + BUCKET_NAME,<br>)<br><br>input_variables = [&quot;chat_history&quot;, &quot;agent_scratchpad&quot;, &quot;input&quot;]<br>prompt = PromptTemplate.from_template(prompt_string)<br>prompt = prompt=hub.pull(&quot;hwchase17/react&quot;)<br><br><br>def react_builder(<br>    model: BaseLanguageModel,<br>    *,<br>    tools: Sequence[BaseTool],<br>    prompt: PromptTemplate,<br>    agent_executor_kwargs = None,<br>    **kwargs,<br>):<br>    from langchain.agents.react.agent import create_react_agent<br>    from langchain.agents import AgentExecutor<br><br>    agent = create_react_agent(llm, [pandas_calculator,csv_summary_statistics,generate_column], prompt)<br>    return AgentExecutor(agent=agent, tools=tools, **agent_executor_kwargs)<br><br>agent = reasoning_engines.LangchainAgent(<br>    model=model,<br>    tools=[pandas_calculator,csv_summary_statistics,generate_column],<br>    prompt=prompt,<br>    agent_executor_kwargs={&quot;verbose&quot;: True}, # Optional. For illustration.<br>    runnable_builder=react_builder,<br>)</pre><p>…and add some wrappers for chat history.</p><pre>#chat history functions<br><br>chat_history = ConversationBufferWindowMemory(k=10)<br><br>def append_chat_history(input, response):<br>    chat_history.save_context({&quot;input&quot;: input}, {&quot;output&quot;: response})<br><br>    <br>def invoke(msg):<br>    if (msg):<br><br>        msg_add_history = {<br>            &quot;input&quot;: msg,<br>            &quot;chat_history&quot;: chat_history.load_memory_variables({}),<br>        }<br>                <br>        response = agent.query(input=msg_add_history)<br><br>        append_chat_history(response[&quot;input&quot;], response[&quot;output&quot;])<br>        <br>        return response[&quot;output&quot;]<br>    else:<br>        return &quot;&quot;</pre><h3>Testing Out the Agent</h3><p>Let’s wrap the agent inside a simple custom UI:.</p><pre>import ipywidgets as widgets<br>from IPython.display import display, clear_output, HTML<br><br><br># Create text box for user input<br>user_input = widgets.Textarea(<br>    value=&#39;&#39;,<br>    placeholder=&#39;Enter text here...&#39;,<br>    layout=widgets.Layout(width=&#39;100%&#39;)<br>)<br><br># Create output area for conversation display<br>conversation_history = widgets.Output()<br>display(conversation_history)<br><br># Create button for user to click to send their message<br>send_button = widgets.Button(description=&#39;Send&#39;)<br><br>def send_button_clicked(b):<br>    with conversation_history:<br>        # User message with gray bubble<br>        user_message = f&quot;&quot;&quot;<br>        &lt;div style=&quot;display: flex; align-items: flex-start;&quot;&gt;<br>            &lt;div style=&quot;background-color: lightgray; padding: 10px; border-radius: 10px; margin-right: 10px;&quot;&gt;<br>                {user_input.value}<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &quot;&quot;&quot;<br>        display(HTML(user_message))<br><br>        # Get chatbot response<br>        response = invoke(user_input.value)<br><br>        # AI response with blue bubble<br>        ai_message = f&quot;&quot;&quot;<br>        &lt;div style=&quot;display: flex; align-items: flex-start; justify-content: flex-end;&quot;&gt;<br>            &lt;div style=&quot;background-color: lightblue; padding: 10px; border-radius: 10px; margin-left: 10px;&quot;&gt;<br>                {response}<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &quot;&quot;&quot;<br>        display(HTML(ai_message))<br><br>        # Clear user input box<br>        user_input.value = &#39;&#39;<br><br>send_button.on_click(send_button_clicked)<br><br># Display the input box and send button<br>display(widgets.HBox([user_input, send_button]))<br></pre><p>Now are are ready to start asking some questions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*DVXRUTLp_aZX6KrKWSoGlg.png" /></figure><p>Note how the agent was able to reason with the help of the ReAct framework about the number of rows. This was a question that our advanced LLM was not able to answer directly. The agentic framework helps the LLM work through a problem step-by-step.</p><p>Let’s look at a more complex follow-up query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*vD8qkHQZQNC2thFIZdn9ZQ.png" /></figure><p>The agent leveraged the pandas_calculator tool by running some pandas commands to come up with an answer. Let’s ask a much more complex question which requires the following reasoning steps:</p><ol><li>coming up with a set of categories</li><li>going through each row one by one and generating a category for each</li><li>counting the number of rows for each category</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*62cepMWQM1wA6AVSXuNltg.png" /></figure><p>This query leveraged the “generate_column” Tool heavily to perform this task to perform the following tasks:</p><ol><li>Get the user question and rewrite the question for better understanding</li><li>Send the prompt to a Python apply function and generate a category for every single row on a new column</li><li>Create and export a new modified file name with the new generated column</li><li>Pass the new file name back to the agent</li></ol><p>Let’s peak under the covers of the <em>generate_column Tool</em> to see how it was designed:</p><pre>@tool(&quot;generate_column&quot;, return_direct=False)<br>def generate_column(dictionary:str):<br>    &quot;&quot;&quot;<br>    For some tasks the column that is needed does not exist and needs to be generated via LLM<br>    This function will loop through each row and fill in the column via some prompt instructions<br>    Inputs should be in format {\&quot;csv_input_file\&quot;: str, &quot;prompt_instructions&quot;:str, &quot;column_name&quot;:str}<br>    <br>    csv_input_file: is the file to be loaded<br>    column_name: is the name of the new column that will be generated<br>    prompt_instructions: is the prompt used by the LLM to generate the column. This will be applied to <br>    each row based on function: df[column_name] = df.apply(lambda x: llm.generate(prompt_instructions + &quot;\n row context&quot; + x + &quot;\n result:\n&quot;))<br>    &quot;&quot;&quot;<br>    <br>    llm = ChatVertexAI(model=&quot;gemini-1.5-pro-002&quot;)<br>    <br>    dictionary = json.loads(dictionary)<br>    input_path = dictionary[&quot;csv_input_file&quot;]<br>    prompt_instructions = dictionary[&quot;prompt_instructions&quot;]<br>    column_name = dictionary[&quot;column_name&quot;]<br>    <br>    prompt_prefix = &quot;&quot;&quot;Follow the instructions, be to the point and do not do anything outside of the<br>                    &quot;instructions. <br>                    <br>                    INSTRUCTIONS:<br>                    answer should be concise<br>                    answer should not have a newline character<br>                    answer should not have any special characters<br>                    <br>                    &quot;&quot;&quot;<br><br>    better_prompt_instructions = llm.invoke(f&quot;&quot;&quot;can you help me rewrite this prompt to a better more specific prompt<br>                                            Each of these instructions will be applied to &quot;this row&quot; please specify that<br>                                            if the answer needs be categorical please come up with the proper categories in brackets: i.e. [cat1, cat2]<br>                                        <br>                                            <br>                                            EXAMPLE: <br>                                            <br>                                            PROMPT: does this refer to a cat or a dog<br>                                            NEW PROMPT: for this specific row does this refer to one of the following categories [cat,dog] pick one as your answer<br>                                            <br>                                            Please only focus on the task of writing one specific prompt, do not provide any additional information or explanation<br>                                            <br>                                            PROMPT:<br>                                            {prompt_instructions}<br>                                            <br>                                            NEW PROMPT:&quot;&quot;&quot;).content<br>    <br>    print(&quot;rewrite prompt to :&quot; + better_prompt_instructions)<br>    <br>    def generate_column(row, prompt_instructions):<br>        prompt = f&quot;{prompt_prefix} \nINSTRUCTIONS: {better_prompt_instructions} \nCONTEXT ROW: {row.to_string()} \nANSWER:&quot;<br>        return llm.invoke(prompt).content  <br>        <br>    df = pd.read_csv(input_path)<br>    df[column_name] = df.apply(lambda x:generate_column(x, prompt_instructions).strip(), axis=1)<br>    filename = &#39;files/modified_file_name.csv&#39;<br>    df.to_csv(filename, index=False) <br><br>    return filename</pre><p>Note the amount of prompting and coding that is being designed for this task.</p><h3>Wrapping Up</h3><p>Hope this was a good starting point to developing your own custom GenAI Analytics applications. Don’t forget that there are a few more things to be done in order to productionalize like error handling and proper evaluation testing. Good luck getting started!</p><p>Links:</p><ul><li><a href="https://github.com/felipecastrillon/FelipesGenAIExplorer/blob/main/csv_analyzer.ipynb">Full Code - Github</a></li><li><a href="https://api.python.langchain.com/en/latest/agents/langchain.agents.agent.AgentExecutor.html">LangChain AgentExecutor reference</a></li><li><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/overview">LangChain on Vertex</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c2dc65fd4e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/custom-genai-analyzer-for-spreadsheet-ninjas-6c2dc65fd4e5">Custom GenAI Analyzer for Spreadsheet Ninjas</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving GenAI Pain Points with Google’s Conversational Agents.]]></title>
            <link>https://medium.com/google-cloud/solving-genai-pain-points-with-googles-conversational-agents-3081c0f93b0e?source=rss-dc92563779fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3081c0f93b0e</guid>
            <category><![CDATA[conversational-ai]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <dc:creator><![CDATA[Fcastrillon]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 16:26:47 GMT</pubDate>
            <atom:updated>2024-12-20T00:43:09.328Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Co-written with </em><a href="https://medium.com/@vijayjohnb/following"><em>Vijay John-Britto</em></a> <em>from Google Cloud</em></p><h3>Introduction</h3><p>Today, enterprises are leveraging GenAI to build useful and intuitive conversational chatbots for their users, but this is without challenges. At first there is a lot excitement with a quick “Time to Pilot” wins which quickly subside as they try to move to production. Here are some of the pain points that enterprise face today:</p><ol><li>Lack of flexibility in the agent building and maintenance process</li><li>Getting inconsistent low-quality responses for some user questions</li><li>Integrating enterprise data systems is non-trivial</li><li>Serving to thousands or millions of customer requires operational best practices</li></ol><p>In this blog we tackle these issues with the help of Google Cloud’s Conversational Agents. Let’s take a closer look.</p><h3>Point Point # 1: Lack of flexibility in the agent building and maintenance process</h3><p>The traditional way of building agents with intents, forms and pages is complex and cumbersome. What’s more, this process is not scalable as you add new intents or actions to your flow. This is where GenAI models can help to develop high quality, comprehensive agents without a huge learning curve.</p><p>Google’s Conversational Agents rely on Natural Language instructions which provides highly flexible conversational flows. This makes it simpler to build and design the flow to a desired outcome. Let’s look at an example on the figure below; let’s say we want to build a Travel agent to enable users to look for places and book tickets. In the image below you can see how simple natural language instructions can guide the main steering agent to handle user requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gM_tauByQmrmTGODizQ6gQ.png" /></figure><p>To go into a bit more depth notice the Goal section where you can define the agent’s persona and the context. The Context and Instructions section outlines the steps for handling tasks in simple natural language.</p><p>Also note that agent business functions can be broken down into smaller, more manageable components using sub-agents. This modular approach streamlines the development process while making ongoing management and updates much easier. Additionally, it improves scalability and allows for the creation of more complex and adaptable agents.</p><p>For the Travel agent, the steering agent is the main agent and has sub- agents for places of search, booking a hotel and others. Depending on the user question the Steering agent will flow into the appropriate sub-agent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9T07YUJ3xAAF-cCy" /></figure><h3>Paint Point #2 Getting inconsistent low-quality responses</h3><p>After building out your Instructions and Goals you should be getting reasonable answers for your commonly tested questions. However, you will likely still get some inconsistent answers from your edge cases or infrequent questions. In this section we provide some options to improve the overall quality of responses.</p><p>Your first decision is to choose the right model. Google Conversational Agents are powered by the Gemini family (currently Gemini Pro 1.5, Gemini 1.5 Flash with more models available soon). Gemini Pro is better suited to help answer more complex questions while Gemini Flash is well suited for higher volume and latency. Depending on your use case and needs you might want to consider either model.</p><p>The next step is getting answers from reliable sources. Conversational Agents have the ability to connect to your enterprise data stores (see next section) to help to ensure the agent’s responses are cited with source references from where the responses are derived. With this feature, agents can deliver high-quality responses with the proper citation of the sources of information used in responses.</p><p>Let’s say we want to ask the Travel agent on Air Travel TSA related questions. It answers the question with the citation to the source reference document which is accurate and verifiable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ee5LbeodRjNFraYQ" /></figure><p>Finally, you need to add some examples to show the agent how to handle some edge cases where it is not performing well. Examples provide the agent with context to use the right sub agents and tools to give high quality answers in the right format with citations. Conversation Agent platform makes it easier to save examples with a one-click option on the top right of your screen.</p><h3>Pain Point # 3: Integrating Enterprise Data systems is non-trivial</h3><p>It is difficult to integrate enterprise data that is spread across various sources and systems (i.e. SaaS applications, websites, file systems and local files) with different formats (HTML, docs, pdfs, figures). Just as difficult it is to ensure that the data is up to date and refreshed.</p><p>Conversational Agents provides built-in seamless integrations with a wide range of data sources, including Google Cloud and popular third-party platforms like OneDrive, Salesforce, and Confluence. This ensures your agent has secure access to the information it needs, empowering it to deliver accurate and informed responses with grounding references. You can find the full list of available connectors <a href="https://cloud.google.com/generative-ai-app-builder/docs/create-datastore-ingest#documents">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBc_ba2SRhnWqzwzCk5MnQ.png" /></figure><p>If your data source does not fit one of the out-of-the-box options available you can connect to internal and external services through APIs to read and write transactional data to complete tasks like search, checking a status, making a reservation or completing a purchase. Conversation Agents have Tools with Open API and Function Calling options to connect to internal and external services in a simple and secure way as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgvXo7VhPTj7EWLgtekrNg.png" /></figure><p>Last but not least, data can be refreshed periodically with a one-click option to keep it in sync on a daily or weekly or monthly basis.</p><h3>Paint Point #4: Serving to thousands or millions of customer requires operational best practices</h3><p>At this point we should have a very high-performant and well-tested agent. The next challenge is to scale agents to your thousands to millions of users and operationalize it seamlessly. It is critical to troubleshoot issues and have auditable traces to get insights on trends and enhance customer experience.</p><p>Conversational Agents are fully managed and can scale up and down based on volume of request. They have comprehensive tools and services built on enterprise grade Google Cloud platform services with tracing, logging, debugging, monitoring security, analytics, continuous evaluation and validation.</p><p>Logging can be enabled at the agent level and logs can be viewed at every conversation level with the corresponding stack trace and timestamp (see example image below). Conversational Agents also offer <a href="https://cloud.google.com/dialogflow/cx/docs/concept/test-case">test cases</a> to evaluate the agent on updates on a continuous basis to ensure consistency and higher quality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FK8lAk2TmjB2puWa" /></figure><p>Another challenge that you will face is the auditing and evaluation of performance. Analytics is a critical part of having an agent to capture all the conversations and get insights on it<strong>. </strong>Enabling Conversation history captures every dialog for auditability as shown in the figure below. It enables us to get insights on common questions asked and trends. Conversation history can be exported to BQ to do deep analytics and build visualizations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f6k-bGZrAt-MM9xf" /></figure><p>Conversational Agents can be very well secured and integrated with your existing collaboration platform as in the figure below. It can be embedded on web interfaces and others (Slack, Twilio, Discord, Facebook Messanger..) and secured with OAuth 2.0 with Google Cloud or any common Identity and Access Services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Cz2JrwGR64F4QTD" /></figure><p>Finally, conversational Agents leverage IAM roles to provide secure access and control for developers, viewers, and operators during the agent lifecycle.</p><p><strong>Wrapping Up…</strong></p><p>Google Gemini powered Conversational Agents enable businesses to tackle AI challenges by:</p><ol><li>Building and managing agents effortlessly with natural language,</li><li>Provide consistent high quality responses with grounding and examples.</li><li>Enabling enterprise data integration with connectivity to 1P and 3P data.</li><li>Scaling and operationalizing the agents from prototype to production with a comprehensive suite of dev tools.</li></ol><p><strong>Ready to explore Conversational Agents for your business?</strong></p><ul><li>You can try our Conversational Agents by signing up at <a href="https://console.google.com/">https://console.google.com</a> and access at <a href="https://dialogflow.cloud.google.com/v2/">https://dialogflow.cloud.google.com/v2/</a> .</li><li>You can reach out to our Google Cloud Sales team for more information, <a href="https://cloud.google.com/contact/">https://cloud.google.com/contact/</a></li></ul><p><strong>References:</strong></p><ol><li><a href="https://cloud.google.com/products/agent-builder?hl=en">https://cloud.google.com/products/agent-builder?hl=en</a></li><li><a href="https://cloud.google.com/products/agent-builder?hl=en#build-conversational-ai-agents-in-minutes">https://cloud.google.com/products/agent-builder?hl=en#build-conversational-ai-agents-in-minutes</a></li><li><a href="https://cloud.google.com/generative-ai-app-builder/docs/introduction">https://cloud.google.com/generative-ai-app-builder/docs/introduction</a></li><li><a href="https://cloud.google.com/products/agentspace">https://cloud.google.com/products/agentspace</a> (latest announcement )</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3081c0f93b0e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/solving-genai-pain-points-with-googles-conversational-agents-3081c0f93b0e">Solving GenAI Pain Points with Google’s Conversational Agents.</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entity Resolution with Text Embeddings on Google Cloud Platform]]></title>
            <link>https://medium.com/google-cloud/entity-resolution-with-text-embeddings-on-google-cloud-11f8d5375fcc?source=rss-dc92563779fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/11f8d5375fcc</guid>
            <category><![CDATA[vector-search]]></category>
            <category><![CDATA[vector-embeddings]]></category>
            <category><![CDATA[vertex-ai]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[entity-resolution]]></category>
            <dc:creator><![CDATA[Fcastrillon]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 20:06:32 GMT</pubDate>
            <atom:updated>2024-12-04T06:44:10.836Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Co-written with </em><a href="https://www.linkedin.com/in/chasfiorenza/"><em>Chas Fiorenza</em></a><em> from Google Cloud</em></p><p>Manually looking through massive data to find and get rid of duplicates is just not practical. Can you imagine trying to find duplicate businesses on 100 million entries? Or linking duplicate accounts for 20 million users?</p><p>Besides the scale, there are several data quality issues as entities might have missing information, slight spelling changes, or descriptions that basically mean the same thing but are worded differently. Recent advances in <a href="https://blog.google/technology/ai/decade-deep-learning-and-whats-next/">Deep Learning</a> have made deduplication techniques to address these issues via embeddings possible. This is not only scalable but can address the many issues at once.</p><p>In this blog, we’ll dive into techniques on how to find duplicate records using Google Cloud products like Vector Search, BigQuery, and <a href="https://arxiv.org/abs/2403.20327">Text Gecko</a> with methods like syntactic and semantic matching.</p><h3>Vector Embeddings</h3><h4>Fundamentals</h4><p>Entity resolution involves locating similar records in a dataset. Extremely similar records are often duplicates and should be rectified.</p><p>In many cases, duplicates are the result of typos that lead to small differences <em>(Ex: Misissippi vs. Mississippi)</em>. Other duplicates may contain semantic differences <em>(Ex: Coffee Shop, Cafe)</em>. Semantically similar records are often analogous despite containing totally different letters/characters.</p><p>In either case, finding similar records is more complicated than filtering with Regex functions like shown below.</p><pre>SELECT * FROM products WHERE REGEXP_CONTAINS(product_name, r’(?i)Pixel);</pre><p>Embeddings can provide a quantitative measure of the semantic and syntactic closeness between records. This vector representation is created using an Embeddings Model <em>(read more </em><a href="https://cloud.google.com/blog/topics/developers-practitioners/meet-ais-multitool-vector-embeddings?e=48754805"><em>here</em></a><em>)</em>. Once entities are converted into embeddings they can be loaded into a vector database and searched in multidimensional space.</p><p><em>Figure 1</em> shows the complete process of creating embeddings, loading the embeddings into a vector database, and querying the results for similar matches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*o0z41_8YeabrmM44" /><figcaption><strong>Figure 1.</strong> Vector Embeddings in Practice</figcaption></figure><h4>Semantic Embeddings: Similarity from Meaning</h4><p>Semantic embeddings have gained popularity since they were popularized in Google’s <a href="https://arxiv.org/pdf/1301.3781">Word2Vec paper</a> in 2013. This has only accelerated with the advent of GenAI applications and RAG architectures.</p><p>Semantic text embeddings represent a numerical vector representation of natural language, i.e. a word, sentence, paragraph.What makes them useful is that they are designed in a way that texts with close semantic meaning are close to each other in the vector space.</p><p>Figure 2 shows examples of semantic similarity between different texts, where related texts have higher semantic similarity (i.e. “World War II” and “Battle of Kursk” have a similarity of 0.71).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DJywQ6CtW95EddKp" /><figcaption><strong>Figure 2.</strong> Analyzing Semantic Similarity of various utterances based on pairwise cosine distance. Similarity scores range from 0 to 1.</figcaption></figure><p>You can already start to imagine how this could be very useful for entity resolution. For example, In a product catalog, a <em>“rubber hammer”</em> product will be similar to a <em>“mallet”</em> but far away from a <em>“drill bit”</em>. In a CRM platform, a <em>“dentist office”</em> is similar to an <em>“orthodontist office”</em> but not similar to a <em>“hardware store”</em>.</p><h4>Syntactic Embeddings: Similarity from Text Tokens</h4><p>In the entity resolution space, not every similarity will be semantic. For example, consider two addresses: <em>“123 Main Street ‘’</em> and <em>“123 Maine Street”</em>. While these two examples might not be semantically similar they are very similar in syntax and could represent a one-letter typo of the same entity.</p><p>There are many ways to find syntactic similarity including edit distance algorithms (i.e. Levensthein or Hamming distance) which measures the minimum number of single-character operations (addition, subtraction, substitutions) to match one string to another.</p><p>For entity resolution applications which requires accounting for various structured fields, a token-based approach like N-Gram vectors are preferred since they can be combined together and even merged with semantic embeddings (see next section). There are many ways to implement an Ngram model in python, with a common libraries like <a href="https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html">scikit CountVectorizer</a>.</p><h4>Combined Hybrid Embeddings Approach</h4><p>In order to combine both semantic and syntactic approaches we have to take into account some design considerations relating to your data. For each field you want to decide what sort of embedding approach makes sense to apply.</p><p>As an example, consider the entities on Table 1. Take the phone number or SKU fields which might have some character typos and will likely benefit from syntactic embeddings. . Alternatively, some fields that rely on descriptions or categories will benefit from semantic embeddings where finding relevant meaning is more important. These can include product description or business industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hTaCNtYh9_-JL5kDShOveA.png" /></figure><p>Once you make your design decisions and have the resulting list of fields with their corresponding embedding vectors, we now have to find a way to combine these. A common way to do this is the concatenation approach where you concatenate all of these vectors together into one long vector.</p><p>Unless your number of fields is small the resulting vector will have too many dimensions and suffer in performance when calculating any similarity function. In this case you want to consider some dimensionality reduction techniques like Principal Component Analysis (PCA), Linear Discriminant Analysis (LDA) or Autoencoders. Google Cloud BigQuery comes with an <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create-autoencoder#example">out of the box feature</a> for the latter</p><h3>GCP Implementation</h3><p>First and foremost you are going to need an embedding model. Google Cloud’s <a href="https://cloud.google.com/model-garden?e=48754805&amp;hl=en">Model Garden</a> offers the first-party <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings">text embedding model</a> backed by Google’s <a href="https://arxiv.org/abs/2403.20327">recent research</a>. You can also search and find for other third-party embedding models in the Model Garden.</p><p>Next, you will decide on a database that can store and serve vectors. GCP offers vector support in AlloyDB, Cloud SQL, Spanner, Vector Search, and BigQuery. For simplicity, this blog will focus on Vertex AI Vector Search and BigQuery.</p><p><a href="https://cloud.google.com/vertex-ai/docs/vector-search/overview">Vertex AI Vector Search</a> is designed to execute low latency Approximate Nearest Neighbor <em>(ANN) </em>queries on billions of records. This managed service is an implementation of the <a href="https://research.google/blog/announcing-scann-efficient-vector-similarity-search/">ScaNN</a> framework and provides a variety of helpful features like metadata filtering. Metadata filtering allows users to bound ANN queries using attributes from the underlying object. For example, when searching for duplicate business entities, it might be helpful to restrict the search to specific countries or states. Vector Search also supports <a href="https://cloud.google.com/vertex-ai/docs/vector-search/setup/format-structure#input_data_processing">hybrid embeddings</a> that are essential for the combined hybrid approach (see previous section).</p><p><a href="https://cloud.google.com/bigquery/docs/vector-index">Vector Indexes in BigQuery</a> are are designed for batch use cases where latency isn’t a primary concern. The following methods are natively available:</p><ul><li><strong>IVF Index:</strong> The Inverted File Index uses k-means clustering to partition the embeddings and reduce the search space. This implementation works well for small datasets due to lower overhead.</li><li><strong>TreeAH Index: </strong>This search technique is based on <a href="https://github.com/google-research/google-research/blob/master/scann/docs/algorithms.md">Google’s ScaNN</a> algorithm mentioned above. This indexing method scales more efficiently than an IVF Index and should be explored for larger datasets. You can read more about TreeAH indexes in this <a href="https://cloud.google.com/blog/products/data-analytics/introducing-scann-in-bigquery-vector-search-for-large-query-batches?e=48754805">release blog</a>.</li></ul><p>Vector indexes organize embeddings using k-means to reduce search complexity. Ultimately this reduces query time and cost compared to a brute force search where the distance between every record is calculated.</p><h4>Complete Architecture</h4><p>Duplicate records can be resolved as they’re created or during a batch audit process. I will call these options <em>“On Insert”</em> and <em>“Offline Reconciliation”. </em>Offline meaning duplicates are reconciled during a scheduled or ad-hoc job.</p><p>On-Insert involves comparing new records with all existing records. This is accomplished using an ANN query in any of the databases mentioned above. <em>Figure 4</em> shows an example Offline Reconciliation architecture. Notice how an ETL tool (i.e. Dataflow) orchestrates the process and converts a sample business entity into an embedding. Next, Vector Search is used to compare this entity with existing records. If the record doesn’t exist, it’s inserted into the destination. If the record exists, attributes can be updated using predefined merge logic. This logic typically contains business rules such as favoring attributes from a specific source system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*HF_U2DRxWFJDeFkX" /><figcaption><strong>Figure 4.</strong> On Insert Entity Resolution</figcaption></figure><p>Locating duplicate records in an existing dataset is typically accomplished with pairwise matching or clustering. These two approaches are described in more details below. Figure 5 shows an example of an offline architecture. Notice how records are inserted and downstream batch processing locates duplicates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*IHPtfJApyhyMWqdU" /><figcaption><strong>Figure 5.</strong> Offline Reconciliation Entity Resolution</figcaption></figure><ol><li><strong>Pairwise matching</strong> describes comparing each record <em>(embedding)</em> with every other record in the database. An ANN style query is executed for every record in the database to locate possible duplicates. This option requires careful design. The type query is known as a high cardinality self cross-join and is computationally expensive.</li><li><strong>Clustering</strong> is another approach to Offline Reconciliation. The goal is to land duplicate records in the same cluster. Many algorithms require the number of clusters to be predetermined. Unfortunately these models can’t be used since the number of duplicates is unknown. Models like Hierarchical Clustering and DBScan can be tested; however, this is an ongoing area of research.</li></ol><h4>Embedding Visualizer</h4><p>Designing an entity resolution tool requires a deep understanding of the data and real world objects represented. Data exploration is an important step of model selection.</p><p>A 3D representation of embeddings can help reveal underlying patterns and offer an initial, qualitative assessment of a model with similar entities ideally in tight clusters.</p><p>The open source <a href="https://www.tensorflow.org/tensorboard/tensorboard_projector_plugin">Embeddings Projector</a> tool hosted on TensorFlow was designed for this purpose. The TensorBoard project can be launched in a Jupyter Notebook to plot embeddings in 3D space. Typically embeddings/vectors are hundreds or thousands of dimensions and difficult to visualize. The Embeddings Projector distills these large vectors down to three dimensions. The example below shows business entity embeddings plotted in 3D. Notice how clusters have formed containing similar entities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ND7hFTpkmyDOu0FZ" /></figure><h3>Quick Recap</h3><ul><li>Finding duplicates from massive datasets is hard</li><li>Recent advances in embeddings can help improve performance</li><li>Syntactic and Semantic similarity can be combined via hybrid embedding approaches</li><li>GCP provides the tools to build an e2e entity resolution system</li></ul><p>Let’s get building!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11f8d5375fcc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/entity-resolution-with-text-embeddings-on-google-cloud-11f8d5375fcc">Entity Resolution with Text Embeddings on Google Cloud Platform</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>