<?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 Deepika Kaushal on Medium]]></title>
        <description><![CDATA[Stories by Deepika Kaushal on Medium]]></description>
        <link>https://medium.com/@deepika.gupta85?source=rss-c6ea7269a4d3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*d7C5260VW3kvUWCY.jpg</url>
            <title>Stories by Deepika Kaushal on Medium</title>
            <link>https://medium.com/@deepika.gupta85?source=rss-c6ea7269a4d3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:31:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepika.gupta85/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[Building Smart AI Agents with LangChain: Wikipedia Search & Image Generation]]></title>
            <link>https://medium.com/@deepika.gupta85/building-ai-agents-with-langchain-2b7bca8ebe08?source=rss-c6ea7269a4d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b7bca8ebe08</guid>
            <dc:creator><![CDATA[Deepika Kaushal]]></dc:creator>
            <pubDate>Thu, 06 Mar 2025 09:58:02 GMT</pubDate>
            <atom:updated>2025-03-07T04:01:46.164Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Artificial Intelligence (AI) agents are transforming the way we interact with information. By integrating powerful tools like Wikipedia for retrieving text-based knowledge and DALL·E for generating images, we can build versatile AI agents capable of answering complex queries and visualizing concepts dynamically. In this article, we’ll explore how to create an AI agent that leverages Wikipedia for text retrieval and DALL·E for image generation.</p><h3>Understanding Agentic AI</h3><p>Agentic AI refers to AI systems that can autonomously make decisions, retrieve external information, and generate responses. These agents interact with users, process inputs, and utilize tools to enhance their functionality. In our case, we will develop an agent that uses 2 tools:</p><ol><li>Searches Wikipedia for relevant information.</li><li>Generates images using DALL·E based on user queries.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y8fJlGqd-ecPN9VWQVYeKQ.jpeg" /><figcaption>Framework for Agentic AI</figcaption></figure><p>You can find the detailed Jupyter notebook here on my github-<a href="https://github.com/deepikakaush/AIAgent">https://github.com/deepikakaush/AIAgent</a></p><h3>Tools and Libraries Required</h3><p>To build our AI agent, we’ll use:</p><ul><li><strong>LangChain</strong>: A powerful framework for building AI-driven applications.</li><li><strong>Wikipedia API Wrapper</strong>: To fetch relevant articles from Wikipedia.</li><li><strong>DALL·E API</strong>: To generate images from text descriptions.</li><li><strong>OpenAI API</strong>: To power the agent’s reasoning capabilities.</li></ul><h3>Getting started</h3><h4>Step 1: Install Dependencies</h4><p>First, install the necessary Python libraries:</p><pre>#Importing the required packages<br>from langchain_community.tools import WikipediaQueryRun  # pip install wikipedia<br>from langchain_community.utilities import WikipediaAPIWrapper<br>from langchain_community.tools.openai_dalle_image_generation import (<br>   OpenAIDALLEImageGenerationTool<br>)<br>from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper<br>from langchain_openai import OpenAI<br>import os<br>from langchain_openai import ChatOpenAI<br>from langchain_core.tools import tool<br>from langchain.tools.render import format_tool_to_openai_function<br>from langchain.schema import SystemMessage<br>from langgraph.prebuilt import create_react_agent<br>from langchain_openai import ChatOpenAI<br>from langchain_core.messages import HumanMessage, AIMessageChunk, SystemMessage</pre><h4>Steps 2: Setting the API keys</h4><pre>#Loading the API Keys from OpenAI <br>os.environ[&quot;OPENAI_API_KEY&quot;]=&#39;sk..&#39;<br>llm_gpt4o = OpenAI(model=&quot;gpt-4o&quot;)<br>chat_model = ChatOpenAI(<br>    api_key=&quot;sk..&quot;<br>     <br>)</pre><h4>Step 3: Creating the AI Agent</h4><p>We now integrate these tools into an AI agent powered by OpenAI’s GPT model.</p><p>This initializes an AI agent that can dynamically choose whether to fetch information from Wikipedia or generate an image with DALL·E based on the user’s query.</p><pre>from langchain_community.agent_toolkits.load_tools import load_tools<br>tools = load_tools([&quot;dalle-image-generator&quot;,&quot;wikipedia&quot;])<br><br>functions = [format_tool_to_openai_function(t) for t in tools]<br>model_with_tools = chat_model.bind_functions(functions=functions)</pre><h4>Step 4: Running the AI Agent</h4><p>Now, let’s test our agent :</p><pre>def execute(agent, query):<br>   response = agent.invoke({&#39;messages&#39;: [HumanMessage(query)]})<br>  <br>   for message in response[&#39;messages&#39;]:<br>       print(<br>           f&quot;{message.__class__.__name__}: {message.content}&quot;<br>       )  # Print message class name and its content<br>      <br>       print(&quot;-&quot; * 20, end=&quot;\n&quot;)<br>  <br>   return response<br>agent = create_react_agent(chat_model, tools, state_modifier=system_prompt)<br>response = execute(agent, query=&#39;Can you plan for 3 days trip to Paris. Also, generate a picture of the city with Eiffel tower?&#39;)</pre><p>This query will trigger the Wikipedia search tool to fetch relevant information about the Paris as well as generate an image using DALL·E.</p><p>The system gave me a Wiki information on Paris, a three day itinerary and this beautiful image was created as an output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fB-rMK5fL8iN_L7CHRZs8Q.jpeg" /><figcaption>Wikipedia search on Paris</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dK-WpvbtHuct-twa9Q0-3Q.jpeg" /><figcaption>3 day itinerary to Paris as an output</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F30DjB58RWNxP69ucRqo_w.jpeg" /><figcaption>Picture of Eiffel Tower generated by Dall.E</figcaption></figure><h3>Conclusion</h3><p>By combining Wikipedia’s vast textual knowledge with DALL·E’s creative image generation capabilities, we can build powerful AI agents that offer rich, multimodal responses. This approach can be extended to many applications, including education, research, and content creation.</p><p>Try implementing this AI agent and experiment with different enhancements like memory, multi-turn conversations, and improved image prompts!</p><h3>What’s Next?</h3><ul><li>Explore integrating other data sources like Google Search or YouTube.</li><li>Improve image prompt engineering for better DALL·E outputs.</li><li>Deploy the agent as a chatbot or a web app using FastAPI or Streamlit.</li></ul><p>What AI-powered tools are you planning to build? Let’s discuss in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b7bca8ebe08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Retrieval-Augmented Generation (RAG) Using Ollama: Retrieve smarter responses-all…]]></title>
            <link>https://medium.com/@deepika.gupta85/implementing-retrieval-augmented-generation-rag-using-ollama-822447edc0a2?source=rss-c6ea7269a4d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/822447edc0a2</guid>
            <dc:creator><![CDATA[Deepika Kaushal]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 09:50:53 GMT</pubDate>
            <atom:updated>2025-03-03T10:02:32.748Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Implementing Retrieval-Augmented Generation (RAG) Using Ollama: R</strong>etrieve smarter responses-all locally &amp; privately!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nn1StRD-mFmkGel9.png" /></figure><p>Retrieval-Augmented Generation (RAG) is a powerful technique that enhances language models by integrating real-time information retrieval. By fetching relevant knowledge from external sources, RAG improves accuracy, reduces hallucinations, and ensures more context-aware responses. Ollama, a lightweight and efficient framework for running large language models locally, provides an excellent platform for implementing RAG with speed and flexibility.</p><h3>Why Use RAG with Ollama?</h3><ul><li><strong>Local and Private Processing</strong> — Ollama runs models directly on your machine, eliminating the need for external API calls and ensuring complete data privacy.</li><li><strong>Enhanced Context Understanding</strong> — By retrieving relevant documents, the model gains deeper context, leading to more accurate and insightful responses.</li><li><strong>Improved Accuracy</strong> — RAG minimizes reliance on a model’s static knowledge, reducing misinformation and keeping responses up to date.</li></ul><h3>How RAG works?</h3><p>RAG works on the principle of chunks and vector database search</p><p><strong>1. Chunks</strong></p><ul><li>Large texts are broken into <strong>smaller chunks</strong> (e.g., sentences or paragraphs).</li><li>This enables more precise retrieval instead of searching entire documents.</li><li>Chunking helps the model access focused and relevant context, improving response quality.</li></ul><p><strong>2. Vector Database Search 🔍</strong></p><ul><li>Each chunk is converted into a <strong>vector embedding</strong> (a numerical representation) using an embedding model.</li><li>These embeddings are stored in a <strong>vector database</strong> (e.g., FAISS, ChromaDB, Pinecone) for fast lookup.</li><li>When a query is made, it is also transformed into an embedding and compared with stored vectors using <strong>similarity search</strong> (e.g., cosine similarity).</li><li>The most relevant chunks are retrieved and used to <strong>augment</strong> the model’s response.</li></ul><p>This process ensures <strong>faster, more accurate, and context-aware AI-generated answers.</strong></p><h3>Steps to Implement RAG Using Ollama</h3><p>You can download and install Ollama from the official site: <a href="https://ollama.com/download/windows">Ollama for Windows</a>.</p><p>Check out my Python implementation of RAG with Ollama on GitHub: <a href="https://github.com/deepikakaush/RAG_Ollama">RAG_Ollama Repository</a>. 🚀</p><h3>Detailed step by step implementation</h3><h4>1. Install and Set Up Ollama</h4><pre>!pip install ollama</pre><h4>2. Load the dataset</h4><p>Since Ollama runs offline, we need to specify the dataset’s location and load it manually. I’ve used a text file named <strong>test.txt</strong>, which you can download from my GitHub repository:</p><p>📂 <strong>Download here:</strong> <a href="https://github.com/deepikakaush/RAG_Ollama">GitHub — RAG_Ollama</a></p><p>Once downloaded, you can load the dataset in Python as follows:</p><pre>import os<br>os.chdir(r&#39;C:\Users\x\Downloads&#39;)<br><br># Load the dataset<br>dataset = []<br>with open(&#39;test.txt&#39;, &#39;r&#39;,encoding=&quot;utf8&quot;) as file:<br>  dataset = file.readlines()<br>  print(f&#39;Loaded {len(dataset)} entries&#39;)</pre><h4>3. Implement the Retrieval Mechanism</h4><p>To enable RAG, the dataset is first divided into smaller chunks, which are then stored in a vector database. When a query is made, relevant content is retrieved using cosine similarity, ensuring precise and context-aware responses.</p><pre><br># Implement the retrieval system<br><br>EMBEDDING_MODEL = &#39;hf.co/CompendiumLabs/bge-base-en-v1.5-gguf&#39;<br>LANGUAGE_MODEL = &#39;hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF&#39;<br><br># Each element in the VECTOR_DB will be a tuple (chunk, embedding)<br># The embedding is a list of floats, for example: [0.1, 0.04, -0.34, 0.21, ...]<br>VECTOR_DB = []<br><br>def add_chunk_to_database(chunk):<br>  embedding = ollama.embed(model=EMBEDDING_MODEL, input=chunk)[&#39;embeddings&#39;][0]<br>  VECTOR_DB.append((chunk, embedding))<br><br>for i, chunk in enumerate(dataset):<br>  add_chunk_to_database(chunk)<br>  print(f&#39;Added chunk {i+1}/{len(dataset)} to the database&#39;)<br><br>def cosine_similarity(a, b):<br>  dot_product = sum([x * y for x, y in zip(a, b)])<br>  norm_a = sum([x ** 2 for x in a]) ** 0.5<br>  norm_b = sum([x ** 2 for x in b]) ** 0.5<br>  return dot_product / (norm_a * norm_b)<br><br>def retrieve(query, top_n=3):<br>  query_embedding = ollama.embed(model=EMBEDDING_MODEL, input=query)[&#39;embeddings&#39;][0]<br>  # temporary list to store (chunk, similarity) pairs<br>  similarities = []<br>  for chunk, embedding in VECTOR_DB:<br>    similarity = cosine_similarity(query_embedding, embedding)<br>    similarities.append((chunk, similarity))<br>  # sort by similarity in descending order, because higher similarity means more relevant chunks<br>  similarities.sort(key=lambda x: x[1], reverse=True)<br>  # finally, return the top N most relevant chunks<br>  return similarities[:top_n]<br><br></pre><h4>4. Generate Augmented Response</h4><p>You can start querying your dataset with the code below.</p><pre><br># Chatbot query<br><br>input_query = input(&#39;Ask me a question on anything: &#39;)<br>retrieved_knowledge = retrieve(input_query)<br><br>print(&#39;Retrieved knowledge:&#39;)<br>for chunk, similarity in retrieved_knowledge:<br>  print(f&#39; - (similarity: {similarity:.2f}) {chunk}&#39;)<br><br>instruction_prompt = f&#39;&#39;&#39;You are a helpful chatbot.<br>Use only the following pieces of context to answer the question. Don&#39;t make up any new information:<br>{&#39;\n&#39;.join([f&#39; - {chunk}&#39; for chunk, similarity in retrieved_knowledge])}<br>&#39;&#39;&#39;<br># print(instruction_prompt)<br><br>stream = ollama.chat(<br>  model=LANGUAGE_MODEL,<br>  messages=[<br>    {&#39;role&#39;: &#39;system&#39;, &#39;content&#39;: instruction_prompt},<br>    {&#39;role&#39;: &#39;user&#39;, &#39;content&#39;: input_query},<br>  ],<br>  stream=True,<br>)<br><br># print the response from the chatbot in real-time<br>print(&#39;Chatbot response:&#39;)<br>for chunk in stream:<br>  print(chunk[&#39;message&#39;][&#39;content&#39;], end=&#39;&#39;, flush=True)</pre><h3>Conclusion</h3><p>Implementing RAG with Ollama enables efficient, accurate, and context-aware responses using local models. By integrating retrieval mechanisms like FAISS, we enhance language models with external knowledge, improving their reliability and usability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=822447edc0a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leveraging RAG (Retrieval-Augmented Generation) for Excel Spreadsheets]]></title>
            <link>https://medium.com/@deepika.gupta85/leveraging-rag-retrieval-augmented-generation-for-excel-spreadsheets-44167e54f027?source=rss-c6ea7269a4d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/44167e54f027</guid>
            <dc:creator><![CDATA[Deepika Kaushal]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 10:03:34 GMT</pubDate>
            <atom:updated>2025-02-28T10:13:02.072Z</atom:updated>
            <content:encoded><![CDATA[<p>Retrieval-Augmented Generation (RAG) is revolutionizing the way we interact with data by combining retrieval-based search with generative AI. When paired with Excel, this approach unlocks powerful insights, allowing users to query, analyze, and generate responses based on structured and unstructured data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*CobcIIMtPqAeQLUfyn6Vxg.jpeg" /></figure><h3><strong>Why Use RAG with Excel?</strong></h3><p>Excel is a widely used tool for data management, but it lacks advanced AI-driven capabilities for contextual search and synthesis. By integrating RAG using <strong>LlamaIndex</strong>, we can bridge this gap, enabling users to:</p><ul><li>Retrieve relevant data from large Excel sheets quickly.</li><li>Generate natural language summaries and insights.</li><li>Answer complex queries based on structured tables and external knowledge sources.</li></ul><h4><strong>How LlamaIndex Enhances Excel with RAG</strong></h4><p>LlamaIndex serves as the data framework that connects Excel spreadsheets with LLMs. Here’s how it works:</p><ol><li><strong>Ingesting Data</strong> — Excel sheets are loaded into LlamaIndex, converting them into query able indices.</li><li><strong>Retrieval Layer</strong> — When a user inputs a query, LlamaIndex fetches the most relevant data from the Excel sheet.</li><li><strong>Generation with Context</strong> — The retrieved data is passed to an LLM, which generates an informed response.</li></ol><h3><strong>Getting Started</strong></h3><p>To implement this, you can use Python with libraries like llama-index,llama-parse, pandas, and openpyxl to load Excel data, create an index, and enable intelligent querying.</p><h4>API Keys Setup</h4><p>I will be using APIs from <strong>OpenAI</strong> (GPT-4o model) and <strong>LlamaCloud</strong>. You can generate your API keys by creating accounts:</p><ul><li><strong>LlamaIndex</strong>: <a href="https://cloud.llamaindex.ai/">Llama Cloud</a></li><li><strong>OpenAI</strong>: <a href="https://platform.openai.com/">OpenAI Platform</a></li></ul><p>The complete Python notebook can be found here: <a href="https://github.com/deepikakaush/AI/tree/main">GitHub Repository</a></p><p>I am using the publicly available dataset <strong>Food Sales</strong>: <a href="https://www.contextures.com/excelsampledatafoodsales.html">Download Dataset</a></p><h4>Explanation of Various Elements in the Code</h4><ul><li><strong>MarkdownElementNodeParser</strong>: In LlamaIndex, this parser processes and structures markdown-formatted text into nodes that can be indexed and retrieved efficiently. It is particularly useful for structured content such as headings, tables, lists, and code blocks.</li><li><strong>VectorStoreIndex</strong>: A crucial component that enables efficient semantic search within data sources like Excel spreadsheets. It transforms text-based data into vector embeddings, making it possible to retrieve relevant information using similarity-based search.</li><li><strong>top_k Parameter</strong>: I have set top_k = 3 to have a more focused response.</li></ul><h3>Code Implementation</h3><p>Importing Required Packages</p><pre>#Importing the packages<br>from llama_index.llms.openai import OpenAI<br>from llama_index.core import VectorStoreIndex<br>from llama_parse import LlamaParse<br>from llama_index.core.node_parser import MarkdownElementNodeParser<br>import pandas as pd<br>import os<br>import nest_asyncio<br>nest_asyncio.apply()</pre><p>Setting API Keys for OpenAI and LlamaParse</p><pre>#Loading the API Keys from OpenAI and Llamacloud<br>os.environ[&quot;OPENAI_API_KEY&quot;]=&#39;sk..&#39;<br>llm_gpt4o = OpenAI(model=&quot;gpt-4o&quot;)<br>parser=LlamaParse(api_key=&#39;llx..&#39;,result_type=&quot;markdown&quot;,)</pre><p>Parsing the excel spreadsheet</p><pre>#Parsing the excel sheet<br>documents = parser.load_data(&quot;sampledatafoodsales.xlsx&quot;)</pre><p>View the content of the document</p><pre>#View the detail of the document<br>print(documents[0].get_content())</pre><p>Parsing the sheet</p><pre>#Parsing the document<br>node_parser = MarkdownElementNodeParser(llm=llm_gpt4o, num_workers=4)<br>nodes = node_parser.get_nodes_from_documents(documents[:5])</pre><p>Dumping Indexed Table into Vector Index for Retrieval</p><pre># dump Indexed table into the vector index<br>recursive_index = VectorStoreIndex(nodes=base_nodes + objects, llm=OpenAI(model=&quot;gpt-4o&quot;))<br><br><br>recursive_query_engine_gpt4o= recursive_index.as_query_engine(<br>    similarity_top_k=5, llm=llm_gpt4o<br>)</pre><p>Here are we finally prompting the pull the required data basis our query</p><pre>#Type your query to retrieve<br>query = &quot;Calculate the total price of product Potato Chips on 20 March 2024. Give reason?&quot;<br>response_recursive_gpt4o = recursive_query_engine_gpt4o.query(query)<br>print(&quot;Here is the output from our GPT model&quot;)<br>display((f&quot;{response_recursive_gpt4o}&quot;))</pre><h3>Conclusion</h3><p>This tutorial demonstrates how to integrate <strong>Retrieval-Augmented Generation (RAG)</strong> with <strong>Excel Spreadsheets</strong> using <strong>LlamaIndex</strong> and <strong>GPT-4o</strong> for intelligent data retrieval and analysis. This approach enhances Excel’s capabilities, making it a more powerful tool for d<strong>ata-driven decision-making</strong>.</p><p>Feel free to connect with me on <strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/deepika-kaushal-98b9948/">Deepika Kaushal</a> 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44167e54f027" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>