<?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 Nikhil Purao on Medium]]></title>
        <description><![CDATA[Stories by Nikhil Purao on Medium]]></description>
        <link>https://medium.com/@nikhilpurao1998?source=rss-2261f56a1efa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3yz8BByII_YW9E1y</url>
            <title>Stories by Nikhil Purao on Medium</title>
            <link>https://medium.com/@nikhilpurao1998?source=rss-2261f56a1efa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:16:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikhilpurao1998/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[How-to Guide for LangGraph]]></title>
            <link>https://medium.com/@nikhilpurao1998/how-to-guide-for-langgraph-3856d49896aa?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/3856d49896aa</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[langchain]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Fri, 30 May 2025 05:43:03 GMT</pubDate>
            <atom:updated>2025-05-30T05:43:03.609Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2kkStFGuVucxu-0nhVNFxA.png" /><figcaption>Image Generated by Gemini</figcaption></figure><p>In the evolving world of large language models (LLMs), building reliable, multi-step conversational applications goes far beyond simple prompts and responses. That’s where <strong>LangGraph</strong> comes in — a powerful framework designed to structure complex LLM workflows using graphs.</p><p>In this post, I’ll walk you through a hands-on guide I’ve created that showcases how to leverage LangGraph to build intelligent agents — ranging from basic chatbots to Retrieval-Augmented Generation (RAG) systems. Whether you’re just getting started with LangGraph or looking to incorporate conditional logic and memory into your LLM apps, this guide is for you. The full code is available <a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph">here</a>.</p><p>We’ll cover:</p><ul><li><a href="https://medium.com/@nikhilpurao1998/building-a-basic-chatbot-with-langgraph-groq-64ffb4756101">Building a basic Chatbot with LangGraph + Groq</a></li><li><a href="https://medium.com/@nikhilpurao1998/programmatic-chat-llms-with-reasoning-control-flow-c77bbc69e6a9">Programmatic Chat: LLMs with Reasoning &amp; Control Flow</a></li><li><a href="https://medium.com/@nikhilpurao1998/retrieval-augmented-generation-rag-using-langgraph-groq-f451494e9317">Retrieval-Augmented Generation (RAG) Using LangGraph + Groq</a></li><li><a href="https://medium.com/@nikhilpurao1998/building-a-rag-based-chatbot-with-langgraph-chroma-and-custom-embeddings-080db8a5fe91">Building a RAG-Based Chatbot with LangGraph, Chroma, and Custom Embeddings</a></li></ul><h3>Building a Basic Chatbot with LangGraph + Groq</h3><p>To kick things off, I created a simple conversational chatbot powered by <strong>Groq’s LLM</strong> and orchestrated with <strong>LangGraph</strong>. This example showcases how to build a <strong>looping chat flow</strong> where user input and model responses are maintained in a structured, state-driven graph.</p><h4>🔧 Setting Up the State Schema</h4><p>We start by defining a <strong>State </strong>object using Python’s <strong>TypedDict</strong>. This represents the evolving state of the chatbot as it runs through different nodes in the graph.</p><pre>class State(TypedDict):<br>    messages: Annotated[list, add_messages]<br>    continue_chat: bool</pre><ul><li>messages: a list of all chat messages (both user and AI).</li><li>continue_chat: a flag to determine whether the conversation should continue.</li></ul><h4>💬 Defining the Chat Flow</h4><p>The chatbot flow is made up of <strong>three main nodes</strong>:</p><blockquote>🗣️ 1. user_speak</blockquote><p>Captures input from the user and appends it to the messages list.</p><pre>def user_speak(state: State) -&gt; State:<br>    user_input = input(&quot;You: &quot;)<br>    state[&quot;messages&quot;].append(HumanMessage(content=user_input))<br>    return state</pre><blockquote>🤖 2. chat</blockquote><p>This is where the magic happens. The model reads the full chat history and generates a response.</p><pre>def chat(state: State) -&gt; State:<br><br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br><br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br><br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br><br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br><br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    # Print the chatbot&#39;s response<br>    print(&quot;Chatbot:&quot;, state[&quot;messages&quot;][-1].content)<br>    return state</pre><blockquote>🔁 3. continue_conversation</blockquote><p>Checks if the user typed &quot;exit&quot;, and sets the flow control accordingly.</p><pre>def continue_conversation(state: State) -&gt; State:<br>    if state[&quot;messages&quot;][-1].content == &quot;exit&quot;:<br>        state[&quot;continue_chat&quot;] = False<br>        print(&quot;Chatbot: Goodbye!&quot;)<br>    else:<br>        state[&quot;continue_chat&quot;] = True<br>    return state</pre><h4>🧭 Connecting the Nodes with LangGraph</h4><p>LangGraph lets us define state transitions using nodes and edges:</p><pre>graph.add_node(&quot;user_speak&quot;, user_speak)<br>graph.add_node(&quot;chat&quot;, chat)<br>graph.add_node(&quot;continue_conversation&quot;, continue_conversation)<br><br>graph.add_edge(START, &quot;user_speak&quot;)<br>graph.add_edge(&quot;user_speak&quot;, &quot;continue_conversation&quot;)<br><br>graph.add_conditional_edges(&quot;continue_conversation&quot;, lambda x: x[&quot;continue_chat&quot;], {<br>    True: &quot;chat&quot;,<br>    False: END<br>})<br><br>graph.add_edge(&quot;chat&quot;, &quot;user_speak&quot;)</pre><p>This sets up a <strong>loop</strong>:</p><ol><li>Ask user for input</li><li>Check if user wants to exit</li><li>If not, generate a response</li><li>Go back to user input</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*ry9VRW-ectSv6rU921_PFw.png" /><figcaption>Figure 1. Basic ChatBot with LangGraph + Groq</figcaption></figure><h3>Programmatic Chat: LLMs with Reasoning &amp; Control Flow</h3><p>While basic chatbots are great for casual conversations, real-world applications often require <strong>logic, validation, and control flow</strong>. In this second example, I created a <strong>programmatic chat system</strong> using LangGraph, where the model:</p><ul><li>Checks if inputs are relevant to a given topic</li><li>Is re-prompted on invalid responses</li><li>And finally, establishes structured relationships between the inputs</li></ul><p>This setup mimics the kind of <strong>multi-step reasoning and quality control</strong> you’d want in educational, analytical, or research-based AI tools.</p><h4>🧠 What’s Happening Behind the Scenes?</h4><p>Firstly there are few more keys in State.</p><pre>class State(TypedDict):<br>    messages: Annotated[list, add_messages]<br>    relevant: bool<br>    input: list<br>    topic: str<br>    retry_limit: int<br>    final_answer: str<br>    answer_again: bool</pre><p>This workflow consists of <strong>five key nodes</strong> in a LangGraph:</p><blockquote>1. ✅ relevancy_check</blockquote><p>Prepares the prompt asking the LLM whether the provided list of concepts is relevant to a given topic.</p><pre>def relevancy_check(state: State) -&gt; State:<br>    topic = state[&#39;topic&#39;]<br>    input_list = state[&#39;input&#39;]<br>    input_str = &quot;&quot;<br>    <br>    for i,inp in enumerate(input_list):<br>        if i == len(input_list):<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>        else:<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>            input_str += &#39;\n&#39;<br>    <br>    human_message = f&quot;&quot;&quot;Are the following elements relevant to the {topic}?<br>    {input_str}<br><br>    Your answer should be Yes or No.<br>    &quot;&quot;&quot;<br>    state[&#39;messages&#39;].append(HumanMessage(content = human_message))<br>                            <br>    return state</pre><blockquote>2. 🧠 call_model_relevancy_check</blockquote><p>Sends the prompt to Groq’s LLM and parses the response:</p><ul><li>If the answer is valid (“Yes”/”No”), it moves forward.</li><li>If the model gives an unclear answer, it sets a retry flag and decrements a retry_limit.</li></ul><p>This logic helps deal with unpredictable LLM outputs while avoiding infinite loops.</p><pre>def call_model_relevancy_check(state: State) -&gt; State:<br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br><br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br><br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br><br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br><br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    <br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br><br>    try:<br>        if response.content.lower() == &quot;yes&quot; or response.content.lower() == &quot;yes.&quot;: # type: ignore<br>            state[&#39;relevant&#39;] = True<br>        elif response.content.lower() == &quot;no&quot; or response.content.lower() == &quot;no.&quot;: # type: ignore<br>            state[&#39;relevant&#39;] = False<br>        state[&#39;answer_again&#39;] = False<br>    except:<br>        try:<br>            if state[&#39;retry_limit&#39;]&gt;0:<br>                state[&#39;answer_again&#39;] = True<br>                state[&#39;retry_limit&#39;] -= 1<br>            else:<br>                state[&#39;answer_again&#39;] = False<br>        except:<br>            state[&#39;retry_limit&#39;] = int(config.get(&quot;LLM_config&quot;, &quot;retry_limit&quot;))<br>            state[&#39;retry_limit&#39;] -= 1<br>            state[&#39;answer_again&#39;] = True<br>    <br>    return state</pre><blockquote>3. 🔁 retry_prompt</blockquote><p>If the model’s answer is invalid (e.g., too verbose or unclear), the model is queried again.</p><pre>def retry_prompt(state: State) -&gt; State:<br><br>    human_message = f&quot;&quot;&quot;You response was not proper.<br>    Your answer should be Yes or No.<br>    &quot;&quot;&quot;<br>    state[&#39;messages&#39;].append(HumanMessage(content = human_message))<br><br>    return state</pre><blockquote>4. 🔗 establish_relationship</blockquote><p>Once relevancy is confirmed, the LLM is prompted to <strong>describe relationships</strong> between items in a structured format:</p><p>How are the following elements related?</p><p>1. Evaporation <br>2. Condensation <br>…</p><p>A -&gt; B -&gt; C <br>A -&gt; D</p><p>It even supports cyclic relationships like A-&gt;B-&gt;C-&gt;A.</p><pre>def establish_relationship(state: State) -&gt; State:<br>    input_list = state[&#39;input&#39;]<br>    input_str = &quot;&quot;<br>    <br>    for i,inp in enumerate(input_list):<br>        if i == len(input_list):<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>        else:<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>            input_str += &#39;\n&#39;<br>    <br>    human_message = f&quot;&quot;&quot;How are following elements related?<br>    {input_str}<br><br>    If A, B, C, D, and E are element and there relationship should be mentioned as follows:<br>    A-&gt;B-&gt;C<br>    A-&gt;D<br>    If there are cyclic relationships then mention it as follows:<br>    A-&gt;B-&gt;C-&gt;A<br>    Do not print anything else.<br>    &quot;&quot;&quot;<br>    state[&#39;messages&#39;].append(HumanMessage(content = human_message))<br>    <br>    return state</pre><blockquote>5. 📤 call_model_establish_relationship</blockquote><p>This node collects the final structured output from the LLM and stores it as final_answer.</p><pre>def call_model_establish_relationship(state: State) -&gt; State:<br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br><br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br><br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br><br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br><br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    <br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br><br>    state[&quot;final_answer&quot;] = response.content # type: ignore<br><br>    return state</pre><h4>🧭 Flow Logic in LangGraph</h4><p>LangGraph makes this branching logic easy to express:</p><pre>graph.add_node(&quot;relevancy_check&quot;, relevancy_check)<br>graph.add_node(&quot;call_model_relevancy_check&quot;, call_model_relevancy_check)<br>graph.add_node(&quot;retry_prompt&quot;, retry_prompt)<br>graph.add_node(&quot;establish_relationship&quot;, establish_relationship)<br>graph.add_node(&quot;call_model_establish_relationship&quot;, call_model_establish_relationship)<br><br>graph.add_edge(START, &quot;relevancy_check&quot;)<br>graph.add_edge(&quot;relevancy_check&quot;, &quot;call_model_relevancy_check&quot;)<br>graph.add_conditional_edges(&quot;call_model_relevancy_check&quot;, lambda x:x[&#39;answer_again&#39;], {<br>    True: &quot;retry_prompt&quot;,<br>    False: &quot;establish_relationship&quot;<br>})<br>graph.add_edge(&quot;retry_prompt&quot;, &quot;call_model_relevancy_check&quot;)<br>graph.add_edge(&quot;establish_relationship&quot;, &quot;call_model_establish_relationship&quot;)<br>graph.add_edge(&quot;call_model_establish_relationship&quot;, END)<br><br># Compile the graph<br>compiled_graph = graph.compile()</pre><p>The graph:</p><ol><li>Starts with a relevancy check</li><li>Retries on failure (up to retry_limit)</li><li>Establishes relationships once inputs are validated</li><li>Ends with a final response</li></ol><h4>🧪 Example Output</h4><p>If you run the following: main([“Evaporation”, “Condensation”, “Precipitation”, “Runoff”, “Infiltration”, “Percolation”, “Transpiration”]). The model responds with something like:</p><p>Evaporation -&gt; Condensation -&gt; Precipitation <br>Precipitation -&gt; Runoff -&gt; Infiltration -&gt; Percolation <br>Transpiration -&gt; Condensation</p><h4>💡 Why This Matters</h4><p>This example demonstrates how <strong>LangGraph empowers LLMs to follow rules, retry intelligently, and execute deterministic flows</strong>. It’s like combining the flexibility of LLMs with the rigour of traditional programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*WArAxMpYJXGX3RmIGTJosw.png" /><figcaption>Figure 2. Programmatic chat with LangGraph+Groq</figcaption></figure><h3>🔍 Retrieval-Augmented Generation (RAG) Using LangGraph + Groq</h3><p>Many real-world applications require AI to <strong>leverage external knowledge</strong> (e.g., PDFs, articles, documentation) — not just predict based on pretraining. That’s where <strong>RAG (Retrieval-Augmented Generation)</strong> comes in.</p><p>In this LangGraph-powered example, I’ve built a complete RAG pipeline where:</p><ul><li>PDF/TXT files are read and embedded</li><li>A vector DB is queried using a natural language question</li><li>An LLM generates a final answer grounded in the retrieved content</li></ul><h4>📦 What Problem Are We Solving?</h4><p>Let’s say a user asks:</p><p><em>“What are the different aspects of the water cycle?”</em></p><p>Instead of relying on the LLM’s memory, we want it to search relevant documents, extract context, and answer accurately using actual source content.</p><p>Embeddings are the backbone of a Retrieval-Augmented Generation (RAG) pipeline. They determine how well your system can understand, represent, and retrieve semantically relevant chunks from your documents.</p><p>By default, many frameworks offer built-in embedding models (like OpenAI or HuggingFace). But in this project, I created a <strong>custom embedding class</strong> using sentence-transformers.</p><pre>class CustomEmbeddings(Embeddings):<br>    def __init__(self, model_name: str):<br>        self.model = SentenceTransformer(model_name)<br><br>    def embed_documents(self, documents: List[str]) -&gt; List[List[float]]:<br>        return [self.model.encode(d).tolist() for d in documents]<br><br>    def embed_query(self, query: str) -&gt; List[float]:<br>        return self.model.encode([query])[0].tolist()</pre><p>This RAG flow is split into <strong>four core nodes</strong></p><blockquote>1. 📂 check_db_exists</blockquote><p>Before doing anything, we check if a <strong>Chroma vector DB</strong> already exists locally:</p><ul><li>Look for chroma.sqlite3 and associated .bin files</li><li>If found → use it</li><li>Else → go to the next step</li></ul><pre>def check_db_exists(state: State) -&gt; State:<br><br>    config_path = &quot;config.ini&quot;    <br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br><br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;persist_directory&quot;)<br>    <br>    # Check if the SQLite database file exists<br>    sql_path = os.path.join(persist_directory, &#39;chroma.sqlite3&#39;)<br>    if not os.path.exists(sql_path):<br>        state[&#39;embeded&#39;] = False<br>        return state<br><br>    subdirs = [<br>        d for d in os.listdir(persist_directory)<br>        if os.path.isdir(os.path.join(persist_directory, d))<br>    ]<br><br>    bin_files_found = any(<br>        len(glob.glob(os.path.join(persist_directory, subdir, &#39;*.bin&#39;))) &gt;= 4<br>        for subdir in subdirs<br>    )<br><br>    if not bin_files_found:<br>        print(&quot;No .bin files found in the vector store.&quot;)<br>        state[&#39;embeded&#39;] = False<br>        return state<br><br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br><br>    print(&quot;Vector store and embeddings are present.&quot;)<br>    persistent_client = chromadb.PersistentClient(path=persist_directory)<br><br>    vector_db = Chroma(<br>    client=persistent_client,<br>    embedding_function=embedding_model)<br><br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&#39;embeded&#39;] = True<br>    return state</pre><blockquote>2. 🧠 emded_documents</blockquote><p>If the DB doesn’t exist, we:</p><ul><li>Extract text from .pdf and .txt files</li><li>Clean the text using regex</li><li>Split it into chunks</li><li>Generate embeddings using sentence-transformers/all-MiniLM-L6-v2</li><li>Store everything in a <strong>persistent Chroma DB</strong></li></ul><p>This sets up our retrieval backend.</p><pre>def emded_documents(state: State) -&gt; State: <br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    <br>    chunk_size = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_size&quot;))<br>    chunk_overlap = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_overlap&quot;))<br>    doc_path = &#39;docs&#39;<br><br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br><br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;PERSIST_DIRECTORY&quot;)<br>    corpus_doc = extract_text_from_pdf_and_txt(doc_path)<br><br>    vector_db = Chroma(<br>    embedding_function=embedding_model,<br>    persist_directory=persist_directory,  # Where to save data locally, remove if not necessary<br>    )<br><br>    document = Document(<br>    page_content = corpus_doc, # type: ignore<br>    # metadata={&quot;source&quot;: &quot;tweet&quot;},<br>    id=1<br>    )<br><br>    text_splitter = RecursiveCharacterTextSplitter(chunk_size = chunk_size, chunk_overlap = chunk_overlap)<br><br>    doc_splits = text_splitter.split_documents([document])<br>    <br>    vector_db.add_documents(doc_splits)<br>                               <br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&quot;embeded&quot;] = True<br>    return state</pre><blockquote>3. 🔍 retrieve</blockquote><p>Now that we have a vector DB:</p><ul><li>We pass in the user’s question</li><li>Retrieve top k most relevant chunks</li><li>Store them in the state[&quot;context&quot;] list</li></ul><pre>def retrieve(state: State):<br><br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    <br>    no_of_chunks = int(config.get(&quot;Embedding_model_config&quot;, &quot;no_of_chunks&quot;))<br><br>    vector_db = state[&quot;vector_db&quot;]<br>    retrieved_docs = vector_db.similarity_search(state[&quot;question&quot;], k = no_of_chunks)<br>    state[&quot;context&quot;] = retrieved_docs<br>    return state</pre><blockquote>4. 🧾 generate</blockquote><p>Finally, we build a new prompt combining:</p><ul><li>The user’s question</li><li>The retrieved document chunks</li></ul><p>Then we pass this enriched context to Groq’s LLM and generate the final answer.</p><pre>def generate(state: State):<br>    <br>    docs_content = &quot;\n\n&quot;.join(doc.page_content for doc in state[&quot;context&quot;])<br>    <br>    question = state[&quot;question&quot;]<br><br>    human_message = f&#39;&#39;&#39;<br>    {question}<br><br>    {docs_content}<br>    &#39;&#39;&#39;<br>    <br>    state[&quot;messages&quot;].append(HumanMessage(content = human_message))<br><br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br><br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br><br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br><br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br><br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br><br>    return state</pre><h4>⚙️ Flow Logic</h4><ol><li>Check if DB exists</li><li>Embed documents if missing</li><li>Retrieve relevant chunks</li><li>Generate grounded response</li></ol><pre>graph.add_node(&quot;check_db_exists&quot;, check_db_exists)<br>graph.add_node(&quot;emded_documents&quot;, emded_documents)<br>graph.add_node(&quot;retrieve&quot;, retrieve)<br>graph.add_node(&quot;generate&quot;, generate)<br><br>graph.add_edge(START, &quot;check_db_exists&quot;)<br>graph.add_conditional_edges(&quot;check_db_exists&quot;, lambda x:x[&quot;embeded&quot;],<br>                            {<br>                                True: &quot;retrieve&quot;,<br>                                False:&quot;emded_documents&quot;<br>                            })<br><br>graph.add_edge(&quot;emded_documents&quot;, &quot;retrieve&quot;)<br>graph.add_edge(&quot;retrieve&quot;, &quot;generate&quot;)<br>graph.add_edge(&quot;generate&quot;, END)</pre><p>This LangGraph+Groq setup turns your LLM into a <strong>truthful, source-grounded assistant</strong>. No hallucinations — just smart retrieval, structured state management, and clean, explainable logic.</p><p>This is the foundation for powerful document Q&amp;A systems, internal knowledge assistants, and educational bots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*mZC2oq-79pHTL0LQx-HZ6Q.png" /><figcaption>Figure 3. Basic RAG setup with LangGraph+Groq</figcaption></figure><h3>🚀 Building a RAG-Based Chatbot with LangGraph, Chroma, and Custom Embeddings</h3><p>Retrieval-Augmented Generation (RAG) is a powerful technique that combines the best of both worlds: grounding large language models (LLMs) in external data sources like PDFs and text files, while preserving the conversational flow of a chatbot. Recently, I built a RAG-based chatbot using <strong>LangGraph</strong>, <strong>Chroma</strong>, and a <strong>custom embedding model</strong> — and it was both fun and educational. I’ll walk you through how I built this system, what architectural decisions I made, and how you can do the same.</p><h3>🔧 Tech Stack Overview</h3><p>Here’s what I used:</p><ul><li><strong>LangGraph</strong>: For declarative state machine-style conversational flows.</li><li><strong>Chroma</strong>: As the vector store to store and search over document embeddings.</li><li><strong>LangChain + SentenceTransformers</strong>: For embeddings using a custom wrapper.</li><li><strong>Groq + Llama3</strong>: For super-fast effective inference.</li></ul><p>Out of the box, LangChain supports many embedding models — but I wanted fine-grained control. So I created a CustomEmbeddings class using Hugging Face’s sentence-transformers/all-MiniLM-L6-v2, which is light, fast, and semantically strong.</p><p>There are 6 nodes to this graph.</p><blockquote>1. 🔍 check_db_exists: Detecting Existing Embeddings</blockquote><p>Before doing any heavy lifting, we check if a <strong>Chroma vector database</strong> with existing embeddings already exists. This is done by looking for:</p><ul><li>A chroma.sqlite3 database file</li><li>Binary .bin files in subdirectories</li></ul><p>If both are found, we can skip re-embedding documents and load the database directly — saving time and compute.</p><p>Recomputing embeddings on every run is wasteful. This step adds persistence and efficiency.</p><pre>def check_db_exists(state: State) -&gt; State:<br><br>    config_path = &quot;config.ini&quot;    <br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br><br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;persist_directory&quot;)<br>    <br>    # Check if the SQLite database file exists<br>    sql_path = os.path.join(persist_directory, &#39;chroma.sqlite3&#39;)<br>    if not os.path.exists(sql_path):<br>        state[&#39;embeded&#39;] = False<br>        return state<br><br>    subdirs = [<br>        d for d in os.listdir(persist_directory)<br>        if os.path.isdir(os.path.join(persist_directory, d))<br>    ]<br><br>    bin_files_found = any(<br>        len(glob.glob(os.path.join(persist_directory, subdir, &#39;*.bin&#39;))) &gt;= 4<br>        for subdir in subdirs<br>    )<br><br>    if not bin_files_found:<br>        print(&quot;No .bin files found in the vector store.&quot;)<br>        state[&#39;embeded&#39;] = False<br>        return state<br><br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br><br>    print(&quot;Vector store and embeddings are present.&quot;)<br>    persistent_client = chromadb.PersistentClient(path=persist_directory)<br><br>    vector_db = Chroma(<br>    client=persistent_client,<br>    embedding_function=embedding_model)<br><br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&#39;embeded&#39;] = True<br>    return state</pre><blockquote>2. 🧾 embed_documents: Creating Vector Representations of Your Corpus</blockquote><p>If no valid vector store is found, we move to this node, which:</p><ol><li>Reads all .pdf and .txt files from the docs/ directory</li><li>Cleans and combines their content</li><li>Splits the text into chunks using a RecursiveCharacterTextSplitter</li><li>Converts each chunk into a vector using our <strong>custom SentenceTransformer embedding model</strong></li><li>Stores those vectors in <strong>Chroma</strong>, with persistence</li></ol><p>The vector database is now ready to power semantic search over your documents.</p><pre>def emded_documents(state: State) -&gt; State: <br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    <br>    chunk_size = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_size&quot;))<br>    chunk_overlap = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_overlap&quot;))<br>    doc_path = &#39;docs&#39;<br><br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br><br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;PERSIST_DIRECTORY&quot;)<br>    corpus_doc = read_texts_and_pdfs(doc_path)<br><br>    vector_db = Chroma(<br>    embedding_function=embedding_model,<br>    persist_directory=persist_directory,  # Where to save data locally, remove if not necessary<br>    )<br><br>    document = Document(<br>    page_content = corpus_doc, # type: ignore<br>    # metadata={&quot;source&quot;: &quot;tweet&quot;},<br>    id=1<br>    )<br><br>    text_splitter = RecursiveCharacterTextSplitter(chunk_size = chunk_size, chunk_overlap = chunk_overlap)<br><br>    doc_splits = text_splitter.split_documents([document])<br>    <br>    vector_db.add_documents(doc_splits)<br>                               <br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&quot;embeded&quot;] = True<br>    return state</pre><blockquote>3. 💬 user_speak: Accepting Natural Language Queries</blockquote><p>Now that the knowledge base is ready, it’s time to talk. This node simply waits for the user to input a question or command (like &quot;exit&quot;). It also appends the user’s message to the chat history (state[&quot;messages&quot;]) to maintain context. Good chatbots need memory. This stores your conversation history.</p><pre>def user_speak(state: State) -&gt;State:<br>    user_input = input(&quot;You: &quot;)<br>    state[&quot;question&quot;] = user_input<br>    state[&quot;messages&quot;].append(HumanMessage(content = user_input))<br>    return state</pre><blockquote>4. 🔍 retrieve: Finding Relevant Context</blockquote><p>This node performs a <strong>similarity search</strong> against the vector database based on the user’s query. It fetches the top k most relevant document chunks using Chroma’s similarity_search() function, and stores them in state[&quot;context&quot;]. Instead of generating blind answers, we ground the LLM with factual, relevant context.</p><pre>def retrieve(state: State):<br><br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    <br>    no_of_chunks = int(config.get(&quot;Embedding_model_config&quot;, &quot;no_of_chunks&quot;))<br><br>    vector_db = state[&quot;vector_db&quot;]<br>    retrieved_docs = vector_db.similarity_search(state[&quot;question&quot;], k = no_of_chunks) # type: ignore<br>    state[&quot;context&quot;] = retrieved_docs<br>    return state</pre><blockquote>5. 🧠 generate: Producing the LLM Response</blockquote><p>Here’s where the actual LLM (e.g., Mixtral or LLaMA3 via Groq) comes in. We pass both the <strong>user’s query</strong> and the <strong>retrieved context</strong> to the model, and it returns a generated response. The result is appended to state[&quot;messages&quot;], maintaining continuity for future turns.</p><pre>def generate(state: State):<br>    <br>    docs_content = &quot;\n\n&quot;.join(doc.page_content for doc in state[&quot;context&quot;])<br>    <br>    question = state[&quot;question&quot;]<br><br>    human_message = f&#39;&#39;&#39;<br>    {question}<br><br>    {docs_content}<br>    &#39;&#39;&#39;<br>    <br>    state[&quot;messages&quot;].append(HumanMessage(content = human_message))<br><br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path) <br><br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br><br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br><br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br><br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    <br>    # Print the chatbot&#39;s response<br>    print(&quot;RAG-bot:&quot;, state[&quot;messages&quot;][-1].content)<br><br>    return state</pre><blockquote>6. 🔁 continue_conversation: Deciding to Loop or Exit</blockquote><p>This final node checks the last user message. If it’s &quot;exit&quot;, we shut the chatbot down gracefully.<br> Otherwise, we loop back to retrieve → generate → user_speak again. This ensures a conversational loop with a natural exit mechanism.</p><pre>def continue_conversation(state: State) -&gt; State:<br>    if state[&quot;messages&quot;][-1].content == &quot;exit&quot;:<br>        state[&quot;continue_chat&quot;] = False<br>        print(&quot;RAG-bot: Goodbye!&quot;)<br>    else:<br>        state[&quot;continue_chat&quot;] = True<br>    return state</pre><p>Together, these nodes form a powerful, modular architecture for your chatbot — clear, extensible, and efficient.</p><pre>graph.add_node(&quot;check_db_exists&quot;, check_db_exists)<br>graph.add_node(&quot;emded_documents&quot;, emded_documents)<br>graph.add_node(&quot;retrieve&quot;, retrieve)<br>graph.add_node(&quot;generate&quot;, generate)<br>graph.add_node(&quot;user_speak&quot;, user_speak)<br>graph.add_node(&quot;continue_conversation&quot;, continue_conversation)<br><br>graph.add_edge(START, &quot;check_db_exists&quot;)<br>graph.add_conditional_edges(&quot;check_db_exists&quot;, lambda x:x[&quot;embeded&quot;],<br>                            {<br>                                True: &quot;user_speak&quot;,<br>                                False:&quot;emded_documents&quot;<br>                            })<br>graph.add_edge(&quot;emded_documents&quot;, &quot;user_speak&quot;)<br>graph.add_edge(&quot;user_speak&quot;, &quot;continue_conversation&quot;)<br>graph.add_conditional_edges(&quot;continue_conversation&quot;, lambda x: x[&quot;continue_chat&quot;],<br>        {<br>            True: &quot;retrieve&quot;,<br>            False: END<br>        })<br>graph.add_edge(&quot;retrieve&quot;, &quot;generate&quot;)<br>graph.add_edge(&quot;generate&quot;, &quot;user_speak&quot;)</pre><p>The code flow begins with the main() function, where a LangGraph state machine is set up to manage the chatbot’s logic. It first runs check_db_exists to see if document embeddings are already stored in Chroma; if not, embed_documents reads and chunks PDF/TXT files, embeds them using a SentenceTransformer model, and stores them. Once ready, user_speak collects a user question, and retrieve fetches the most relevant chunks from the vector store. These chunks, along with the question, are passed to generate, which uses Groq’s LLM to craft a response. The conversation continues or exits based on continue_conversation, allowing for a seamless loop of user queries and AI responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*ebWSkjE3dLYjyS7qiGu-qA.png" /><figcaption>Figure 4. RAG-based Chatbot with LangGraph+Groq</figcaption></figure><p>Inference and Conclusions:</p><ol><li>The chatbot is implemented using a state-driven design via LangGraph.</li><li>Implements a structured, modular NLP pipeline using LangChain and Groq.</li><li>The code implements a <strong>Retrieval-Augmented Generation (RAG)</strong> pipeline using LangGraph and LangChain components.</li><li>The code also implements a RAG-based chatbot where in retriever fetches chunks based on user-response, but also keeps previous conversation in mind.</li></ol><p>References and Useful links:</p><ol><li><a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph">https://github.com/Nikhilp18/How-to-guide-for-LangGraph</a></li><li><a href="https://langchain-ai.github.io/langgraph/concepts/why-langgraph/">https://langchain-ai.github.io/langgraph/concepts/why-langgraph/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3856d49896aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a RAG-Based Chatbot with LangGraph, Chroma, and Custom Embeddings]]></title>
            <link>https://medium.com/@nikhilpurao1998/building-a-rag-based-chatbot-with-langgraph-chroma-and-custom-embeddings-080db8a5fe91?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/080db8a5fe91</guid>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Fri, 30 May 2025 05:34:19 GMT</pubDate>
            <atom:updated>2025-05-30T05:49:30.772Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nq2rM7RiU3azqQDZButdQw.png" /><figcaption>Image Generated by Gemini</figcaption></figure><p>Retrieval-Augmented Generation (RAG) is a powerful technique that combines the best of both worlds: grounding large language models (LLMs) in external data sources like PDFs and text files, while preserving the conversational flow of a chatbot. Recently, I built a RAG-based chatbot using <strong>LangGraph</strong>, <strong>Chroma</strong>, and a <strong>custom embedding model</strong> — and it was both fun and educational. I’ll walk you through how I built this system, what architectural decisions I made, and how you can do the same. The full code is available <a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph/blob/main/RAG-based_chat_bot.py">here</a>.</p><h3>🔧 Tech Stack Overview</h3><p>Here’s what I used:</p><ul><li><strong>LangGraph</strong>: For declarative state machine-style conversational flows.</li><li><strong>Chroma</strong>: As the vector store to store and search over document embeddings.</li><li><strong>LangChain + SentenceTransformers</strong>: For embeddings using a custom wrapper.</li><li><strong>Groq + Llama3</strong>: For super-fast effective inference.</li></ul><p>Out of the box, LangChain supports many embedding models — but I wanted fine-grained control. So I created a CustomEmbeddings class using Hugging Face’s sentence-transformers/all-MiniLM-L6-v2, which is light, fast, and semantically strong.</p><p>There are 6 nodes to this graph.</p><blockquote>1. 🔍 <em>check_db_exists</em>: Detecting Existing Embeddings</blockquote><p>Before doing any heavy lifting, we check if a <strong>Chroma vector database</strong> with existing embeddings already exists. This is done by looking for:</p><ul><li>A chroma.sqlite3 database file</li><li>Binary .bin files in subdirectories</li></ul><p>If both are found, we can skip re-embedding documents and load the database directly — saving time and compute. Recomputing embeddings on every run is wasteful. This step adds persistence and efficiency.</p><pre>def check_db_exists(state: State) -&gt; State:<br>    config_path = &quot;config.ini&quot;    <br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;persist_directory&quot;)<br>    <br>    # Check if the SQLite database file exists<br>    sql_path = os.path.join(persist_directory, &#39;chroma.sqlite3&#39;)<br>    if not os.path.exists(sql_path):<br>        state[&#39;embeded&#39;] = False<br>        return state<br>    subdirs = [<br>        d for d in os.listdir(persist_directory)<br>        if os.path.isdir(os.path.join(persist_directory, d))<br>    ]<br>    bin_files_found = any(<br>        len(glob.glob(os.path.join(persist_directory, subdir, &#39;*.bin&#39;))) &gt;= 4<br>        for subdir in subdirs<br>    )<br>    if not bin_files_found:<br>        print(&quot;No .bin files found in the vector store.&quot;)<br>        state[&#39;embeded&#39;] = False<br>        return state<br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br>    print(&quot;Vector store and embeddings are present.&quot;)<br>    persistent_client = chromadb.PersistentClient(path=persist_directory)<br>    vector_db = Chroma(<br>    client=persistent_client,<br>    embedding_function=embedding_model)<br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&#39;embeded&#39;] = True<br>    return state</pre><blockquote>2. 🧾 <em>embed_documents</em>: Creating Vector Representations of Your Corpus</blockquote><p>If no valid vector store is found, we move to this node, which:</p><ol><li>Reads all .pdf and .txt files from the docs/ directory</li><li>Cleans and combines their content</li><li>Splits the text into chunks using a RecursiveCharacterTextSplitter</li><li>Converts each chunk into a vector using our <strong>custom SentenceTransformer embedding model</strong></li><li>Stores those vectors in <strong>Chroma</strong>, with persistence</li></ol><p>The vector database is now ready to power semantic search over your documents.</p><pre>def emded_documents(state: State) -&gt; State: <br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    <br>    chunk_size = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_size&quot;))<br>    chunk_overlap = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_overlap&quot;))<br>    doc_path = &#39;docs&#39;<br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;PERSIST_DIRECTORY&quot;)<br>    corpus_doc = read_texts_and_pdfs(doc_path)<br>    vector_db = Chroma(<br>    embedding_function=embedding_model,<br>    persist_directory=persist_directory,  # Where to save data locally, remove if not necessary<br>    )<br>    document = Document(<br>    page_content = corpus_doc, # type: ignore<br>    # metadata={&quot;source&quot;: &quot;tweet&quot;},<br>    id=1<br>    )<br>    text_splitter = RecursiveCharacterTextSplitter(chunk_size = chunk_size, chunk_overlap = chunk_overlap)<br>    doc_splits = text_splitter.split_documents([document])<br>    <br>    vector_db.add_documents(doc_splits)<br>                               <br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&quot;embeded&quot;] = True<br>    return state</pre><blockquote>3. 💬 <em>user_speak</em>: Accepting Natural Language Queries</blockquote><p>Now that the knowledge base is ready, it’s time to talk. This node simply waits for the user to input a question or command (like &quot;exit&quot;). It also appends the user’s message to the chat history (state[&quot;messages&quot;]) to maintain context. Good chatbots need memory. This stores your conversation history.</p><pre>def user_speak(state: State) -&gt;State:<br>    user_input = input(&quot;You: &quot;)<br>    state[&quot;question&quot;] = user_input<br>    state[&quot;messages&quot;].append(HumanMessage(content = user_input))<br>    return state</pre><blockquote>4. 🔍 <em>retrieve</em>: Finding Relevant Context</blockquote><p>This node performs a <strong>similarity search</strong> against the vector database based on the user’s query. It fetches the top k most relevant document chunks using Chroma’s similarity_search() function, and stores them in state[&quot;context&quot;]. Instead of generating blind answers, we ground the LLM with factual, relevant context.</p><pre>def retrieve(state: State):<br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    <br>    no_of_chunks = int(config.get(&quot;Embedding_model_config&quot;, &quot;no_of_chunks&quot;))<br>    vector_db = state[&quot;vector_db&quot;]<br>    retrieved_docs = vector_db.similarity_search(state[&quot;question&quot;], k = no_of_chunks) # type: ignore<br>    state[&quot;context&quot;] = retrieved_docs<br>    return state</pre><blockquote>5. 🧠 <em>generate</em>: Producing the LLM Response</blockquote><p>Here’s where the actual LLM (e.g., Mixtral or LLaMA3 via Groq) comes in. We pass both the <strong>user’s query</strong> and the <strong>retrieved context</strong> to the model, and it returns a generated response. The result is appended to state[&quot;messages&quot;], maintaining continuity for future turns.</p><pre>def generate(state: State):<br>    <br>    docs_content = &quot;\n\n&quot;.join(doc.page_content for doc in state[&quot;context&quot;])<br>    <br>    question = state[&quot;question&quot;]<br>    <br>    human_message = f&#39;&#39;&#39;<br>    {question}<br>    {docs_content}<br>    &#39;&#39;&#39;<br>    <br>    state[&quot;messages&quot;].append(HumanMessage(content = human_message))<br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path) <br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    <br>    # Print the chatbot&#39;s response<br>    print(&quot;RAG-bot:&quot;, state[&quot;messages&quot;][-1].content)<br>    return state</pre><blockquote>6. 🔁 <em>continue_conversation</em>: Deciding to Loop or Exit</blockquote><p>This final node checks the last user message. If it’s &quot;exit&quot;, we shut the chatbot down gracefully.<br> Otherwise, we loop back to retrieve → generate → user_speak again. This ensures a conversational loop with a natural exit mechanism.</p><pre>def continue_conversation(state: State) -&gt; State:<br>    if state[&quot;messages&quot;][-1].content == &quot;exit&quot;:<br>        state[&quot;continue_chat&quot;] = False<br>        print(&quot;RAG-bot: Goodbye!&quot;)<br>    else:<br>        state[&quot;continue_chat&quot;] = True<br>    return state</pre><p>Together, these nodes form a powerful, modular architecture for your chatbot — clear, extensible, and efficient.</p><pre>graph.add_node(&quot;check_db_exists&quot;, check_db_exists)<br>graph.add_node(&quot;emded_documents&quot;, emded_documents)<br>graph.add_node(&quot;retrieve&quot;, retrieve)<br>graph.add_node(&quot;generate&quot;, generate)<br>graph.add_node(&quot;user_speak&quot;, user_speak)<br>graph.add_node(&quot;continue_conversation&quot;, continue_conversation)<br><br>graph.add_edge(START, &quot;check_db_exists&quot;)<br>graph.add_conditional_edges(&quot;check_db_exists&quot;, lambda x:x[&quot;embeded&quot;],<br>                            {<br>                                True: &quot;user_speak&quot;,<br>                                False:&quot;emded_documents&quot;<br>                            })<br>graph.add_edge(&quot;emded_documents&quot;, &quot;user_speak&quot;)<br>graph.add_edge(&quot;user_speak&quot;, &quot;continue_conversation&quot;)<br>graph.add_conditional_edges(&quot;continue_conversation&quot;, lambda x: x[&quot;continue_chat&quot;],<br>        {<br>            True: &quot;retrieve&quot;,<br>            False: END<br>        })<br>graph.add_edge(&quot;retrieve&quot;, &quot;generate&quot;)<br>graph.add_edge(&quot;generate&quot;, &quot;user_speak&quot;)</pre><p>The code flow begins with the main() function, where a LangGraph state machine is set up to manage the chatbot’s logic. It first runs check_db_exists to see if document embeddings are already stored in Chroma; if not, embed_documents reads and chunks PDF/TXT files, embeds them using a SentenceTransformer model, and stores them. Once ready, user_speak collects a user question, and retrieve fetches the most relevant chunks from the vector store. These chunks, along with the question, are passed to generate, which uses Groq’s LLM to craft a response. The conversation continues or exits based on continue_conversation, allowing for a seamless loop of user queries and AI responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*ebWSkjE3dLYjyS7qiGu-qA.png" /><figcaption>Figure 1. RAG-based Chatbot with LangGraph+Groq</figcaption></figure><h4>Inference and Conclusion:</h4><ol><li>Embeds and stores documents locally using ChromaDB. Enables persistent context retrieval without re-embedding unless needed.</li><li>Uses all-MiniLM-L6-v2 — a lightweight but powerful SentenceTransformer model ideal for fast, cost-effective similarity search.</li><li>Employs LangGraph to structure flow: user input → document retrieval → response generation.</li><li>Each question results in a retrieval and generation cycle, meaning the LLM “remembers” previous turns carried in state[&quot;messages&quot;].</li></ol><h4>Reference and Useful links:</h4><ol><li><a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph">https://github.com/Nikhilp18/How-to-guide-for-LangGraph</a></li><li><a href="https://langchain-ai.github.io/langgraph/concepts/why-langgraph/">https://langchain-ai.github.io/langgraph/concepts/why-langgraph/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=080db8a5fe91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retrieval-Augmented Generation (RAG) Using LangGraph + Groq]]></title>
            <link>https://medium.com/@nikhilpurao1998/retrieval-augmented-generation-rag-using-langgraph-groq-f451494e9317?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f451494e9317</guid>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[langgraph-tutorial]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[openai]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Wed, 28 May 2025 21:25:19 GMT</pubDate>
            <atom:updated>2025-05-30T05:52:29.400Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fxtQfoWZerNbUb6M1XwTeA.png" /><figcaption>Image Generated by Gemini</figcaption></figure><p>Many real-world applications require AI to <strong>leverage external knowledge</strong> (e.g., PDFs, articles, documentation) — not just predict based on pretraining. That’s where <strong>RAG (Retrieval-Augmented Generation)</strong> comes in. The full code is available <a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph/blob/main/RAG.py">here</a>. In this LangGraph-powered example, I’ve built a complete RAG pipeline where:</p><ul><li>PDF/TXT files are read and embedded</li><li>A vector DB is queried using a natural language question</li><li>An LLM generates a final answer grounded in the retrieved content</li></ul><h4>📦 What Problem Are We Solving?</h4><p>Let’s say a user asks:</p><p><em>“What are the different aspects of the water cycle?”</em></p><p>Instead of relying on the LLM’s memory, we want it to search relevant documents, extract context, and answer accurately using actual source content.</p><p>Embeddings are the backbone of a Retrieval-Augmented Generation (RAG) pipeline. They determine how well your system can understand, represent, and retrieve semantically relevant chunks from your documents.</p><p>By default, many frameworks offer built-in embedding models (like OpenAI or HuggingFace). But in this project, I created a <strong>custom embedding class</strong> using sentence-transformers.</p><pre>class CustomEmbeddings(Embeddings):<br>    def __init__(self, model_name: str):<br>        self.model = SentenceTransformer(model_name)<br>    def embed_documents(self, documents: List[str]) -&gt; List[List[float]]:<br>        return [self.model.encode(d).tolist() for d in documents]<br>    def embed_query(self, query: str) -&gt; List[float]:<br>        return self.model.encode([query])[0].tolist()</pre><p>This RAG flow is split into <strong>four core nodes</strong></p><blockquote>1. 📂 <em>check_db_exists</em></blockquote><p>Before doing anything, we check if a <strong>Chroma vector DB</strong> already exists locally:</p><ul><li>Look for chroma.sqlite3 and associated .bin files</li><li>If found → use it</li><li>Else → go to the next step</li></ul><pre>def check_db_exists(state: State) -&gt; State:<br>    config_path = &quot;config.ini&quot;    <br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;persist_directory&quot;)<br>    <br>    # Check if the SQLite database file exists<br>    sql_path = os.path.join(persist_directory, &#39;chroma.sqlite3&#39;)<br>    if not os.path.exists(sql_path):<br>        state[&#39;embeded&#39;] = False<br>        return state<br>    subdirs = [<br>        d for d in os.listdir(persist_directory)<br>        if os.path.isdir(os.path.join(persist_directory, d))<br>    ]<br>    bin_files_found = any(<br>        len(glob.glob(os.path.join(persist_directory, subdir, &#39;*.bin&#39;))) &gt;= 4<br>        for subdir in subdirs<br>    )<br>    if not bin_files_found:<br>        print(&quot;No .bin files found in the vector store.&quot;)<br>        state[&#39;embeded&#39;] = False<br>        return state<br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br>    print(&quot;Vector store and embeddings are present.&quot;)<br>    persistent_client = chromadb.PersistentClient(path=persist_directory)<br>    vector_db = Chroma(<br>    client=persistent_client,<br>    embedding_function=embedding_model)<br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&#39;embeded&#39;] = True<br>    return state</pre><blockquote>2. 🧠 <em>emded_documents</em></blockquote><p>If the DB doesn’t exist, we:</p><ul><li>Extract text from .pdf and .txt files</li><li>Clean the text using regex</li><li>Split it into chunks</li><li>Generate embeddings using sentence-transformers/all-MiniLM-L6-v2</li><li>Store everything in a <strong>persistent Chroma DB</strong></li></ul><p>This sets up our retrieval backend.</p><pre>def emded_documents(state: State) -&gt; State: <br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    <br>    chunk_size = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_size&quot;))<br>    chunk_overlap = int(config.get(&quot;Embedding_model_config&quot;, &quot;chunk_overlap&quot;))<br>    doc_path = &#39;docs&#39;<br>    embedding_model = CustomEmbeddings(model_name=&quot;sentence-transformers/all-MiniLM-L6-v2&quot;)<br>    persist_directory = config.get(&quot;Embedding_model_config&quot;, &quot;PERSIST_DIRECTORY&quot;)<br>    corpus_doc = extract_text_from_pdf_and_txt(doc_path)<br>    vector_db = Chroma(<br>    embedding_function=embedding_model,<br>    persist_directory=persist_directory,  # Where to save data locally, remove if not necessary<br>    )<br>    document = Document(<br>    page_content = corpus_doc, # type: ignore<br>    # metadata={&quot;source&quot;: &quot;tweet&quot;},<br>    id=1<br>    )<br>    text_splitter = RecursiveCharacterTextSplitter(chunk_size = chunk_size, chunk_overlap = chunk_overlap)<br>    doc_splits = text_splitter.split_documents([document])<br>    <br>    vector_db.add_documents(doc_splits)<br>                               <br>    state[&quot;vector_db&quot;] = vector_db # type: ignore<br>    state[&quot;embeded&quot;] = True<br>    return state</pre><blockquote>3. 🔍 <em>retrieve</em></blockquote><p>Now that we have a vector DB:</p><ul><li>We pass in the user’s question</li><li>Retrieve top k most relevant chunks</li><li>Store them in the state[&quot;context&quot;] list</li></ul><pre>def retrieve(state: State):<br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    <br>    no_of_chunks = int(config.get(&quot;Embedding_model_config&quot;, &quot;no_of_chunks&quot;))<br>    vector_db = state[&quot;vector_db&quot;]<br>    retrieved_docs = vector_db.similarity_search(state[&quot;question&quot;], k = no_of_chunks)<br>    state[&quot;context&quot;] = retrieved_docs<br>    return state</pre><blockquote>4. 🧾 <em>generate</em></blockquote><p>Finally, I built a new prompt combining:</p><ul><li>The user’s question</li><li>The retrieved document chunks</li></ul><p>Then we pass this enriched context to Groq’s LLM and generate the final answer.</p><pre>def generate(state: State):<br>    <br>    docs_content = &quot;\n\n&quot;.join(doc.page_content for doc in state[&quot;context&quot;])<br>    <br>    question = state[&quot;question&quot;]<br>    human_message = f&#39;&#39;&#39;<br>    {question}<br>    {docs_content}<br>    &#39;&#39;&#39;<br>    <br>    state[&quot;messages&quot;].append(HumanMessage(content = human_message))<br>    config_path = &quot;config.ini&quot;<br>    config = configparser.RawConfigParser()<br>    config.read(config_path)<br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    return state</pre><h4>⚙️ Flow Logic</h4><ol><li>Check if DB exists</li><li>Embed documents if missing</li><li>Retrieve relevant chunks</li><li>Generate a grounded response</li></ol><pre>graph.add_node(&quot;check_db_exists&quot;, check_db_exists)<br>graph.add_node(&quot;emded_documents&quot;, emded_documents)<br>graph.add_node(&quot;retrieve&quot;, retrieve)<br>graph.add_node(&quot;generate&quot;, generate)<br><br>graph.add_edge(START, &quot;check_db_exists&quot;)<br>graph.add_conditional_edges(&quot;check_db_exists&quot;, lambda x:x[&quot;embeded&quot;],<br>                            {<br>                                True: &quot;retrieve&quot;,<br>                                False:&quot;emded_documents&quot;<br>                            })<br>graph.add_edge(&quot;emded_documents&quot;, &quot;retrieve&quot;)<br>graph.add_edge(&quot;retrieve&quot;, &quot;generate&quot;)<br>graph.add_edge(&quot;generate&quot;, END)</pre><p>This LangGraph+Groq setup turns your LLM into a <strong>truthful, source-grounded assistant</strong>. No hallucinations — just smart retrieval, structured state management, and clean, explainable logic.</p><p>This is the foundation for powerful document Q&amp;A systems, internal knowledge assistants, and educational bots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*mZC2oq-79pHTL0LQx-HZ6Q.png" /><figcaption>Figure 1. Basic RAG setup with LangGraph+Groq</figcaption></figure><h4>Inference and Conclusions:</h4><ol><li>The code implements a <strong>Retrieval-Augmented Generation (RAG)</strong> pipeline using LangGraph and LangChain components</li><li>Uses a <strong>custom embedding class</strong> (CustomEmbeddings) based on SentenceTransformers.</li><li>Checks if a <strong>Chroma vector database</strong> with valid binary files already exists.</li><li>If not, the documents are embedded and stored in a new Chroma DB.</li><li>Uses RecursiveCharacterTextSplitter to chunk long texts before embedding.</li><li>This RAG pipeline is a <strong>robust and efficient framework</strong> for answering natural language questions based on local documents.</li><li>Combines <strong>retrieval</strong> (vector DB search) with <strong>generation</strong> (LLM completion) for accurate, contextual answers.</li><li>Highly modular and extensible — ideal for applications like internal knowledge assistants or document QA systems.</li></ol><h4>Reference and Useful links:</h4><ol><li><a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph">https://github.com/Nikhilp18/How-to-guide-for-LangGraph</a></li><li><a href="https://langchain-ai.github.io/langgraph/concepts/why-langgraph/">https://langchain-ai.github.io/langgraph/concepts/why-langgraph/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f451494e9317" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programmatic Chat: LLMs with Reasoning & Control Flow]]></title>
            <link>https://medium.com/@nikhilpurao1998/programmatic-chat-llms-with-reasoning-control-flow-c77bbc69e6a9?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/c77bbc69e6a9</guid>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[langgraph-tutorial]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Wed, 28 May 2025 21:11:53 GMT</pubDate>
            <atom:updated>2025-05-28T21:26:56.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uvjo_H0IuZDbqVUCOldLjg.png" /><figcaption>Image generated by Gemini</figcaption></figure><p>While basic chatbots are great for casual conversations, real-world applications often require <strong>logic, validation, and control flow</strong>. In this second example, I created a <strong>programmatic chat system</strong> using LangGraph, where the model:</p><ul><li>Checks if inputs are relevant to a given topic</li><li>Is re-prompted on invalid responses</li><li>And finally, establishes structured relationships between the inputs</li></ul><p>This setup mimics the kind of <strong>multi-step reasoning and quality control</strong> you’d want in educational, analytical, or research-based AI tools. The full code is available <a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph/blob/main/programmatic_chat.py">here</a>.</p><h4>🧠 What’s Happening Behind the Scenes?</h4><p>Firstly there are few more keys in State.</p><pre>class State(TypedDict):<br>    messages: Annotated[list, add_messages]<br>    relevant: bool<br>    input: list<br>    topic: str<br>    retry_limit: int<br>    final_answer: str<br>    answer_again: bool</pre><p>This workflow consists of <strong>five key nodes</strong> in a LangGraph:</p><blockquote>1. ✅ <em>relevancy_check</em></blockquote><p>Prepares the prompt asking the LLM whether the provided list of concepts is relevant to a given topic.</p><pre>def relevancy_check(state: State) -&gt; State:<br>    topic = state[&#39;topic&#39;]<br>    input_list = state[&#39;input&#39;]<br>    input_str = &quot;&quot;<br>    <br>    for i,inp in enumerate(input_list):<br>        if i == len(input_list):<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>        else:<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>            input_str += &#39;\n&#39;<br>    <br>    human_message = f&quot;&quot;&quot;Are the following elements relevant to the {topic}?<br>    {input_str}<br>    Your answer should be Yes or No.<br>    &quot;&quot;&quot;<br>    state[&#39;messages&#39;].append(HumanMessage(content = human_message))<br>                            <br>    return state<br></pre><blockquote>2. 🧠 <em>call_model_relevancy_check</em></blockquote><p>Sends the prompt to Groq’s LLM and parses the response:</p><ul><li>If the answer is valid (“Yes”/”No”), it moves forward.</li><li>If the model gives an unclear answer, it sets a retry flag and decrements a retry_limit.</li></ul><p>This logic helps deal with unpredictable LLM outputs while avoiding infinite loops.</p><pre>def call_model_relevancy_check(state: State) -&gt; State:<br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    <br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    try:<br>        if response.content.lower() == &quot;yes&quot; or response.content.lower() == &quot;yes.&quot;: # type: ignore<br>            state[&#39;relevant&#39;] = True<br>        elif response.content.lower() == &quot;no&quot; or response.content.lower() == &quot;no.&quot;: # type: ignore<br>            state[&#39;relevant&#39;] = False<br>        state[&#39;answer_again&#39;] = False<br>    except:<br>        try:<br>            if state[&#39;retry_limit&#39;]&gt;0:<br>                state[&#39;answer_again&#39;] = True<br>                state[&#39;retry_limit&#39;] -= 1<br>            else:<br>                state[&#39;answer_again&#39;] = False<br>        except:<br>            state[&#39;retry_limit&#39;] = int(config.get(&quot;LLM_config&quot;, &quot;retry_limit&quot;))<br>            state[&#39;retry_limit&#39;] -= 1<br>            state[&#39;answer_again&#39;] = True<br>    <br>    return state</pre><blockquote>3. 🔁 <em>retry_prompt</em></blockquote><p>If the model’s answer is invalid (e.g., too verbose or unclear), the model is queried again.</p><pre>def retry_prompt(state: State) -&gt; State:<br>    human_message = f&quot;&quot;&quot;You response was not proper.<br>    Your answer should be Yes or No.<br>    &quot;&quot;&quot;<br>    state[&#39;messages&#39;].append(HumanMessage(content = human_message))<br>    return state</pre><blockquote>4. 🔗 <em>establish_relationship</em></blockquote><p>Once relevancy is confirmed, the LLM is prompted to <strong>describe relationships</strong> between items in a structured format:</p><p>How are the following elements related?</p><p>1. Evaporation <br>2. Condensation <br>…</p><p>A -&gt; B -&gt; C <br>A -&gt; D</p><p>It even supports cyclic relationships like A-&gt;B-&gt;C-&gt;A.</p><pre>def establish_relationship(state: State) -&gt; State:<br>    input_list = state[&#39;input&#39;]<br>    input_str = &quot;&quot;<br>    <br>    for i,inp in enumerate(input_list):<br>        if i == len(input_list):<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>        else:<br>            input_str += f&#39;{i+1}. {inp}&#39;<br>            input_str += &#39;\n&#39;<br>    <br>    human_message = f&quot;&quot;&quot;How are following elements related?<br>    {input_str}<br>    If A, B, C, D, and E are element and there relationship should be mentioned as follows:<br>    A-&gt;B-&gt;C<br>    A-&gt;D<br>    If there are cyclic relationships then mention it as follows:<br>    A-&gt;B-&gt;C-&gt;A<br>    Do not print anything else.<br>    &quot;&quot;&quot;<br>    state[&#39;messages&#39;].append(HumanMessage(content = human_message))<br>    <br>    return state</pre><blockquote>5. 📤 <em>call_model_establish_relationship</em></blockquote><p>This node collects the final structured output from the LLM and stores it as final_answer.</p><pre>def call_model_establish_relationship(state: State) -&gt; State:<br>    <br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    <br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    state[&quot;final_answer&quot;] = response.content # type: ignore<br>    return state</pre><h4>🧭 Flow Logic in LangGraph</h4><p>LangGraph makes this branching logic easy to express:</p><pre>graph.add_node(&quot;relevancy_check&quot;, relevancy_check)<br>graph.add_node(&quot;call_model_relevancy_check&quot;, call_model_relevancy_check)<br>graph.add_node(&quot;retry_prompt&quot;, retry_prompt)<br>graph.add_node(&quot;establish_relationship&quot;, establish_relationship)<br>graph.add_node(&quot;call_model_establish_relationship&quot;, call_model_establish_relationship)<br><br>graph.add_edge(START, &quot;relevancy_check&quot;)<br>graph.add_edge(&quot;relevancy_check&quot;, &quot;call_model_relevancy_check&quot;)<br>graph.add_conditional_edges(&quot;call_model_relevancy_check&quot;, lambda x:x[&#39;answer_again&#39;], {<br>    True: &quot;retry_prompt&quot;,<br>    False: &quot;establish_relationship&quot;<br>})<br>graph.add_edge(&quot;retry_prompt&quot;, &quot;call_model_relevancy_check&quot;)<br>graph.add_edge(&quot;establish_relationship&quot;, &quot;call_model_establish_relationship&quot;)<br>graph.add_edge(&quot;call_model_establish_relationship&quot;, END)<br># Compile the graph<br>compiled_graph = graph.compile()</pre><p>The graph:</p><ol><li>Starts with a relevancy check</li><li>Retries on failure (up to retry_limit)</li><li>Establishes relationships once inputs are validated</li><li>Ends with a final response</li></ol><h4>🧪 Example Output</h4><p>If you run the following: main([“Evaporation”, “Condensation”, “Precipitation”, “Runoff”, “Infiltration”, “Percolation”, “Transpiration”]). The model responds with something like:</p><p>Evaporation -&gt; Condensation -&gt; Precipitation <br>Precipitation -&gt; Runoff -&gt; Infiltration -&gt; Percolation <br>Transpiration -&gt; Condensation</p><h4>💡 Why This Matters</h4><p>This example demonstrates how <strong>LangGraph empowers LLMs to follow rules, retry intelligently, and execute deterministic flows</strong>. It’s like combining the flexibility of LLMs with the rigour of traditional programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*WArAxMpYJXGX3RmIGTJosw.png" /><figcaption>Figure 1. Programmatic chat with LangGraph+Groq</figcaption></figure><h4><strong>Inference and Conclusions:</strong></h4><ol><li>The code defines a LangGraph-based workflow using the StateGraph structure.</li><li>Prompts the LLM to assess if the elements are relevant to the given topic.</li><li>If relevant, prompts the LLM to establish and return relationships among the elements.</li><li>Implements a structured, modular NLP pipeline using LangChain and Groq.</li><li>Includes retry capability to improve LLM reliability.</li></ol><h4><strong>References and useful links:</strong></h4><ol><li><a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph">https://github.com/Nikhilp18/How-to-guide-for-LangGraph</a></li><li><a href="https://langchain-ai.github.io/langgraph/concepts/why-langgraph/">https://langchain-ai.github.io/langgraph/concepts/why-langgraph/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c77bbc69e6a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Basic Chatbot with LangGraph + Groq]]></title>
            <link>https://medium.com/@nikhilpurao1998/building-a-basic-chatbot-with-langgraph-groq-64ffb4756101?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/64ffb4756101</guid>
            <category><![CDATA[chatgroq]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[langgraph-tutorial]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[langgraph]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Wed, 28 May 2025 20:47:46 GMT</pubDate>
            <atom:updated>2025-05-28T21:28:22.881Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJopmloV6K-fwbGNhygkTg.png" /><figcaption>Image generated using Gemini</figcaption></figure><p>In this project, I built a simple yet dynamic chatbot using <strong>LangGraph</strong> and <strong>Groq API</strong>. The chatbot follows a stateful design, where the entire conversation is tracked and managed using a custom state schema. Configuration details like the model name, temperature, and API key are loaded from a config.ini file to keep things clean and modular. At the core is a state machine, defined using LangGraph’s StateGraph, which orchestrates the flow between user input, AI response, and the decision to continue or end the conversation. The loop continues until the user types &quot;exit&quot;, at which point the bot gracefully ends the session. As a bonus, the entire conversational graph is visualized and saved as a PNG image (basic_chat_bot.png), giving a clear snapshot of the chatbot&#39;s flow. This setup provides a strong foundation for building more advanced conversational agents with modular, inspectable logic.</p><p>To kick things off, I created a simple conversational chatbot powered by <strong>Groq’s LLM</strong> and orchestrated with <strong>LangGraph</strong>. This example showcases how to build a <strong>looping chat flow</strong> where user input and model responses are maintained in a structured, state-driven graph. The full code is available <a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph/blob/main/basic_chat_bot.py">here</a>.</p><h4>🔧 Setting Up the State Schema</h4><p>We start by defining a <strong>State </strong>object using Python’s <strong>TypedDict</strong>. This represents the evolving state of the chatbot as it runs through different nodes in the graph.</p><pre>class State(TypedDict):<br>    messages: Annotated[list, add_messages]<br>    continue_chat: bool</pre><ul><li>messages: a list of all chat messages (both user and AI).</li><li>continue_chat: a flag to determine whether the conversation should continue.</li></ul><h4>💬 Defining the Chat Flow</h4><p>The chatbot flow is made up of <strong>three main nodes</strong>:</p><blockquote>🗣️ 1. <em>user_speak</em></blockquote><p>Captures input from the user and appends it to the messages list.</p><pre>def user_speak(state: State) -&gt; State:<br>    user_input = input(&quot;You: &quot;)<br>    state[&quot;messages&quot;].append(HumanMessage(content=user_input))<br>    return state</pre><blockquote>🤖 2. <em>chat</em></blockquote><p>This is where the magic happens. The model reads the full chat history and generates a response.</p><pre>def chat(state: State) -&gt; State:<br>    config_file = &#39;config.ini&#39;<br>    config = configparser.RawConfigParser()<br>    config.read(config_file)<br>    os.environ[&quot;GROQ_API_KEY&quot;] = config.get(&#39;LLM_config&#39;, &#39;groq_api_key&#39;)<br>    model_name = config.get(&#39;LLM_config&#39;, &#39;model_name&#39;)<br>    model_temperature = int(config.get(&#39;LLM_config&#39;, &#39;model_temperature&#39;))<br>    llm = ChatGroq(model= model_name, temperature = model_temperature)<br>    # Generate a response using the language model<br>    response = llm.invoke(state[&quot;messages&quot;])<br>    # Update the state with the new messages<br>    state[&quot;messages&quot;].append(response)<br>    # Print the chatbot&#39;s response<br>    print(&quot;Chatbot:&quot;, state[&quot;messages&quot;][-1].content)<br>    return state</pre><blockquote>🔁 3. <em>continue_conversation</em></blockquote><p>Checks if the user typed &quot;exit&quot;, and sets the flow control accordingly.</p><pre>def continue_conversation(state: State) -&gt; State:<br>    if state[&quot;messages&quot;][-1].content == &quot;exit&quot;:<br>        state[&quot;continue_chat&quot;] = False<br>        print(&quot;Chatbot: Goodbye!&quot;)<br>    else:<br>        state[&quot;continue_chat&quot;] = True<br>    return state</pre><h4>🧭 Connecting the Nodes with LangGraph</h4><p>LangGraph lets us define state transitions using nodes and edges:</p><pre>graph.add_node(&quot;user_speak&quot;, user_speak)<br>graph.add_node(&quot;chat&quot;, chat)<br>graph.add_node(&quot;continue_conversation&quot;, continue_conversation)<br><br>graph.add_edge(START, &quot;user_speak&quot;)<br>graph.add_edge(&quot;user_speak&quot;, &quot;continue_conversation&quot;)<br>graph.add_conditional_edges(&quot;continue_conversation&quot;, lambda x: x[&quot;continue_chat&quot;], {<br>    True: &quot;chat&quot;,<br>    False: END<br>})<br>graph.add_edge(&quot;chat&quot;, &quot;user_speak&quot;)</pre><p>This sets up a <strong>loop</strong>:</p><ol><li>Ask user for input</li><li>Check if user wants to exit</li><li>If not, generate a response</li><li>Go back to user input</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*ry9VRW-ectSv6rU921_PFw.png" /><figcaption>Figure 1. Basic ChatBot with LangGraph + Groq</figcaption></figure><h4><strong>Inference and conclusion:</strong></h4><ul><li>The chatbot is implemented using a state-driven design via LangGraph.</li><li>It uses ChatGroq for generating responses based on user messages.</li><li>The conversation is looped by checking if the user wants to continue.</li><li>Environment variables and configuration files are used to manage model parameters dynamically.</li><li>The flow is modular, making it easy to modify or extend (e.g., adding memory, RAG, logging).</li></ul><h4>References and useful links:</h4><ol><li><a href="https://github.com/Nikhilp18/How-to-guide-for-LangGraph">https://github.com/Nikhilp18/How-to-guide-for-LangGraph</a></li><li><a href="https://langchain-ai.github.io/langgraph/concepts/why-langgraph/">https://langchain-ai.github.io/langgraph/concepts/why-langgraph/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64ffb4756101" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[American Sign Language Image Data Classification using Neural Network]]></title>
            <link>https://medium.com/@nikhilpurao1998/american-sign-language-image-data-classification-using-neural-network-374b06a0ba17?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/374b06a0ba17</guid>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[american-sign-language]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Sun, 02 Oct 2022 14:28:33 GMT</pubDate>
            <atom:updated>2022-10-02T14:28:33.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ouMOluod6TB2m9--dVeQvg.png" /></figure><p>American Sign Language (ASL) is a comprehensive, natural language with English-like syntax that has many of the same linguistic characteristics as spoken languages. Hand and face gestures are used to convey meaning in ASL. Many deaf and hard-of-hearing individuals in North America use it as their primary language. The precise origins of ASL are unknown, however some believe it evolved more than 200 years ago from the mixing of local sign languages and French Sign Language (LSF). Today’s ASL has certain parts of LSF as well as the original local sign languages; over time, these have merged and developed into a rich, sophisticated, and mature language. Modern ASL and modern LSF are different languages. While they still include some identical indicators, they can no longer be understood by each other’s users.<br>ASL is a fully unique and distinct language from English. It has all of the basic properties of language, including its own rules for pronunciation, word creation, and word order. While every language contains means of indicating distinct purposes, such as asking a question rather than making a statement, the manner in which this is done varies throughout languages.<br>Specific ways of expressing concepts in ASL, as in other languages, vary as much as ASL users themselves. ASL includes regional accents and dialects, much as some English words are spoken differently in different regions of the country; similarly, ASL has regional variations in the rhythm of signing, pronunciation, slang, and signs employed. As with spoken languages, other societal variables such as age and gender can influence ASL usage and add to its diversity. ASL includes fingerspelling, which is used to sign out English words. Each letter in the fingerspell alphabet corresponds to a different handshape. Fingerspelling is frequently employed to signify proper names or the English term for something.</p><p>The dataset contains 26 alphabets classes and 3 special character classes viz. SPACE, DELETE and NOTHING. The training dataset contains 87000 images of 200 x 200 pixels. The dataset is downloaded from Kaggle from the link: <a href="https://www.kaggle.com/datasets/grassknoted/asl-alphabet">https://www.kaggle.com/datasets/grassknoted/asl-alphabet</a></p><p>The image data will be trained on a pre-existing MobileNet CNN model architecture.</p><p><strong>MobileNet:</strong></p><p>MobileNets are a family of TensorFlow mobile-first computer vision models that are developed to optimise accuracy while keeping in mind the limited resources of an on-device or embedded application. MobileNets are low-latency, low-power models that may be customised to fit the resource restrictions of a wide range of use cases. They may be used to build classification, detection, embeddings, and segmentation systems.<br>Depthwise separable convolutions are used by MobileNet. When compared to the network with ordinary convolutions of the same depth in the network, it greatly reduces the number of parameters. As a result, lightweight deep neural networks are created. MobileNet is a CNN class that was open-sourced by Google, providing a fantastic starting point for training our classifiers that are incredibly tiny and extremely fast.</p><h4>Preprocessing the image data:</h4><p>Preprocessing images with preprocessing function of mobilenet and converting image to a target size of 224 x 224 pixel. We will not shuffle the test datasets as we will need its test data-labels later.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D27&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D27&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fe9bff2d3d37a438587b4e3a1fe3010d4%2Fpreview%2F64b27e5ae6854f0c8143035b771f33ba&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/955cc546c0ac6b770c98b9aaa7fc012d/href">https://medium.com/media/955cc546c0ac6b770c98b9aaa7fc012d/href</a></iframe><p><strong>Replacing the prediction layer of MobileNet with the number of classes available in our dataset:</strong></p><p>The original MobileNet model was trained to output 1000 different classes. We will replace with to output 29 distict classes present in our dataset i.e., A-Z and 3 special characters SPACE, DELETE, NOTHING.We will set only last 23 layers out of 88 layers of MobileNet model as trainable and train the model to our dataset.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D34&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D34&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fe9bff2d3d37a438587b4e3a1fe3010d4%2Fpreview%2F64b27e5ae6854f0c8143035b771f33ba&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a2a456ec72a29769f188f3c4200960c/href">https://medium.com/media/5a2a456ec72a29769f188f3c4200960c/href</a></iframe><p>As we can see out of 4.2M parameters, only 2.9M parameters are now trainable.</p><p><strong>Compiling the model</strong></p><p>We will compile the model with following settings:</p><ol><li>Optimizer = Adam</li><li>Learning rate = 0.0001</li><li>Loss function = Categorical crossentropy</li><li>Metric used = Accuracy</li></ol><p><strong>Fitting the model</strong></p><p>We will fit the model with following settings:</p><ol><li>Epochs = 10</li><li>Verbosity = 2</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D39&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D39&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fe9bff2d3d37a438587b4e3a1fe3010d4%2Fpreview%2F64b27e5ae6854f0c8143035b771f33ba&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/21b27eb32b45059ad5572c54442260d3/href">https://medium.com/media/21b27eb32b45059ad5572c54442260d3/href</a></iframe><p>The model is able to achieve an accuracy of about 99% on both training set and validation set respectively at the end of 10th epoch.</p><p><strong>Accuracy of model on test set</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D45&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fcopy-of-asl-image-classification%2Fv%2F1%26cellId%3D45&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fe9bff2d3d37a438587b4e3a1fe3010d4%2Fpreview%2F64b27e5ae6854f0c8143035b771f33ba&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/66c25720c823560a17350710046dce77/href">https://medium.com/media/66c25720c823560a17350710046dce77/href</a></iframe><h3>Inferences and Conclusion</h3><p>The inferences and conclusions made are listed below:</p><ol><li>The dataset was split into training, validation and test sets.</li><li>The predefined MobileNet model is used to train the data.</li><li>The images in the dataset were preprocessed with the preprocessing function of MobileNet.</li><li>The prediction layer of MobileNet was replaced with the number of distinct classes in our dataset.</li><li>Last 23 layers out of 88 layers of MobileNet were set to trainable.</li><li>The model is able to achieve accuracy of 99.89 % and 99.98% on training set and validation set respectively at the end of 10th epoch.</li><li>The model is able to achieve an accuracy of 100% on test dataset</li></ol><h3>References and future work</h3><p>All the useful links are listed below:</p><ol><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Fgrassknoted%2Fasl-alphabet">https://www.kaggle.com/datasets/grassknoted/asl-alphabet</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fdeeplizard.com%2F">https://deeplizard.com/</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fkeras.io%2Fapi%2Fapplications%2Fmobilenet%2F">https://keras.io/api/applications/mobilenet/</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.tensorflow.org%2F">https://www.tensorflow.org/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=374b06a0ba17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stellar Object Classification]]></title>
            <link>https://medium.com/@nikhilpurao1998/stellar-object-classification-6937b4aeb0e4?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/6937b4aeb0e4</guid>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[space]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Sun, 02 Oct 2022 09:23:56 GMT</pubDate>
            <atom:updated>2022-10-02T09:23:56.943Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M_FY7YLDYwEAKaVpw7-0HQ.jpeg" /><figcaption>AI generated image from app ‘Dawn.ai’</figcaption></figure><p>The data consists of 100,000 observations of space taken by the SDSS (Sloan Digital Sky Survey). Every observation is described by 17 feature columns and 1 class column which identifies it to be either a star, galaxy or quasar.</p><ol><li>obj_ID = Object Identifier, the unique value that identifies the object in the image catalog used by the CAS</li><li>alpha = Right Ascension angle (at J2000 epoch)</li><li>delta = Declination angle (at J2000 epoch)</li><li>u = Ultraviolet filter in the photometric system</li><li>g = Green filter in the photometric system</li><li>r = Red filter in the photometric system</li><li>i = Near Infrared filter in the photometric system</li><li>z = Infrared filter in the photometric system</li><li>run_ID = Run Number used to identify the specific scan</li><li>rereun_ID = Rerun Number to specify how the image was processed</li><li>cam_col = Camera column to identify the scanline within the run</li><li>field_ID = Field number to identify each field</li><li>spec_obj_ID = Unique ID used for optical spectroscopic objects (this means that 2 different observations with the same spec_obj_ID must share the output class)</li><li>class = object class (galaxy, star or quasar object)</li><li>redshift = redshift value based on the increase in wavelength</li><li>plate = plate ID, identifies each plate in SDSS</li><li>MJD = Modified Julian Date, used to indicate when a given piece of SDSS data was taken</li><li>fiber_ID = fiber ID that identifies the fiber that pointed the light at the focal plane in each observation</li></ol><p>Stellar classification in astronomy is the division of stars into different categories according to their spectral properties. One of the most fundamental concepts in astronomy is the categorization of galaxies, quasars, and stars. The early cataloguing of stars and their arrangement in the sky led to the realisation that they constituted our own galaxy, and once it was determined that Andromeda was a different galaxy from our own, a number of galaxies started to be studied as more potent telescopes were constructed. This dataset seeks to categorise stars, galaxies, and quasars according to their spectral properties.</p><p>The dataset can be downloaded from kaggle with link given below. <a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Ffedesoriano%2Fstellar-classification-dataset-sdss17">https://www.kaggle.com/datasets/fedesoriano/stellar-classification-dataset-sdss17</a></p><h4><strong>Exploratory Analysis and Visualization</strong></h4><p>In this section, we will plotting the following data:</p><ol><li>Heatmap of correlation matrix of dataset</li><li>Count plot for Galaxies, stars and quasars in space</li><li>Red filter in the photometric system vs Right Ascension angle (at J2000 epoch)</li><li>Green filter vs Ultraviolet filter in the photometric system</li><li>Infrared filter vs Ultraviolet filter in the photometric system</li><li>Declination angle vs Right Ascension angle (at J2000 epoch)</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D25%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D25%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F4819dc2b53f24e14835d44569f5abb78%2Fpreview%2Fe75ae2fb89c743baa0a474c9fb762566&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7deeccea8fb1d659a939ba9b4fbe01ca/href">https://medium.com/media/7deeccea8fb1d659a939ba9b4fbe01ca/href</a></iframe><p>We can see that there is strong correlation between following variables:</p><ol><li>Object Identifier and Run Number</li><li>Plate ID and Unique ID used for optical spectroscopic objects</li><li>Modified Julian Date and Unique ID used for optical spectroscopic objects</li><li>Ultraviolet filter and Green filter</li><li>Ultraviolet filter and Red filter</li><li>Green filter and Near Infrared filter</li><li>Near Infrared filter and Infrared filter</li><li>Red filter and Near Infrared filter</li></ol><p>There is some correlation between following variables:</p><ol><li>Ultraviolet filter and Unique ID used for optical spectroscopic objects</li><li>Green filter and Unique ID used for optical spectroscopic objects</li><li>Unique ID used for optical spectroscopic objects and Red filter</li><li>Unique ID used for optical spectroscopic objects and Infrared filter</li><li>Unique ID used for optical spectroscopic objects and Near Infrared filter</li></ol><p><strong>Univariate Analysis</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D29%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D29%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F4819dc2b53f24e14835d44569f5abb78%2Fpreview%2Fe75ae2fb89c743baa0a474c9fb762566&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ca819a5870b3791b2d7140620ad2a89/href">https://medium.com/media/9ca819a5870b3791b2d7140620ad2a89/href</a></iframe><p>In the given dataset, there are 59,445 galaxies, 21,593 stars and 18,961 quasar objects.</p><p><strong>Bivariate Analysis</strong></p><p>Green filter vs Ultraviolet filter in the photometric system:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D35%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D35%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F4819dc2b53f24e14835d44569f5abb78%2Fpreview%2Fe75ae2fb89c743baa0a474c9fb762566&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b641e9346fc0a939b2cdc7cbdfe0e039/href">https://medium.com/media/b641e9346fc0a939b2cdc7cbdfe0e039/href</a></iframe><p>Infrared filter vs Ultraviolet filter in the photometric system:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D37%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D37%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F4819dc2b53f24e14835d44569f5abb78%2Fpreview%2Fe75ae2fb89c743baa0a474c9fb762566&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8782e108bf7127f19973e867be5c57f5/href">https://medium.com/media/8782e108bf7127f19973e867be5c57f5/href</a></iframe><h4>Model Building</h4><p>In this section, we will be using following models and evaluate their performance on the given dataset:</p><ol><li>Logistic Regression</li><li>Random Forest</li><li>Naive Bayes: GaussianNB</li><li>KNN: KNeighborsClassifier</li><li>Gini tree</li><li>Entropy tree</li><li>Ada boost Classifier</li><li>Support vector Machine</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D59%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fstellar-object-classification%2Fv%2F13%26cellId%3D59%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2F4819dc2b53f24e14835d44569f5abb78%2Fpreview%2Fe75ae2fb89c743baa0a474c9fb762566&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/902fc240c54f3bf1931afa72de6467d3/href">https://medium.com/media/902fc240c54f3bf1931afa72de6467d3/href</a></iframe><p>Various models were used to solve the classification problem. Random Forest classifier gives the highest accuracy amongst all the models. Decision trees with different hyperparameters follows next in accuracy, while Ada Boost Classifier performs the worst.</p><h4>Inferences and Conclusion</h4><p>A thorough analysis was performed 100,000 observations of space taken by the SDSS (Sloan Digital Sky Survey). Several Machine learning models were employed and Random Forest was able to deliver an accuracy of 97.9%. In the given dataset, there are 59,445 galaxies, 21,593 stars and 18,961 quasar objects.</p><h4>References and Future Work</h4><p>All the useful links are listed below:</p><ol><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Ffedesoriano%2Fstellar-classification-dataset-sdss17">https://www.kaggle.com/datasets/fedesoriano/stellar-classification-dataset-sdss17</a></li><li><a href="https://jovian.ai/outlink?url=http%3A%2F%2Fwww.sdss.org%2Fscience%2Fimage-gallery%2F">http://www.sdss.org/science/image-gallery/</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fplotly.com%2F">https://plotly.com/</a></li><li><a href="https://jovian.ai/">https://jovian.ai/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6937b4aeb0e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[E-commerce Data Analysis and Price Prediction]]></title>
            <link>https://medium.com/@nikhilpurao1998/e-commerce-data-analysis-and-price-prediction-8af34e7fb31a?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8af34e7fb31a</guid>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Sun, 02 Oct 2022 08:54:37 GMT</pubDate>
            <atom:updated>2022-10-02T08:54:37.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mI7VllEJkfVXdx7V0bTY-w.jpeg" /><figcaption>AI generated image from the app ‘Dawn.ai’</figcaption></figure><p>The Indian e-commerce business has been expanding rapidly. Following a boom in digital adoption at COVID-19, the Indian e-commerce sector is expected to be worth more than 55 billion dollars in Gross Merchandise Value by 2021. It is predicted to reach a gross merchandise value of 350 billion dollars by 2030. Furthermore, by 2021, over 348 million people were completing online transactions, with approximately 140 million purchasing online.<br>This sector’s primary drivers include a young demographic, increased internet and smartphone usage, and comparatively stronger economic performance. India is now the second largest internet market, with 830 million subscribers. With a 45.4% share in 2021, digital wallets were the biggest payment option for e-commerce purchases.<br>Nearly all pin codes in India have witnessed e-commerce penetration. In India, tier two cities and smaller towns account for more than 60% of all transactions and orders. The e-commerce trend is gaining traction even in tier-2 and tier-3 cities, which now account for roughly half of all customers and three out of every five orders placed on big e-commerce platforms. Tier-2 and smaller towns have slightly lower average selling prices (ASP) than tier-1/metro cities. When measured by transaction value, electronics and clothes account for over 70% of the e-commerce market. Other emerging e-commerce sectors include ed-tech, hyperlocal, and food-tech; E-commerce financing in India increased by 600% year on year in 2021.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D32%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D32%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d0e819504b882b3c5c7ed8e95d8ec82/href">https://medium.com/media/6d0e819504b882b3c5c7ed8e95d8ec82/href</a></iframe><p>About 60% of the products in the datasets are Flipkart assured/Amazon Fulfilled.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D36%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D36%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca5a1af75f4ba8f9bdf0ee4bc76ac4c4/href">https://medium.com/media/ca5a1af75f4ba8f9bdf0ee4bc76ac4c4/href</a></iframe><p>The product distribution on gender basis is given as follows:</p><ol><li>Women: 57.6 %</li><li>Men: 42 %</li><li>Unisex: 0.388 %</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D38%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D38%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2d7798c5e287aca9c5715ecd698982b/href">https://medium.com/media/c2d7798c5e287aca9c5715ecd698982b/href</a></iframe><p>On an average, it has been observed that there are more products listed for women but 5 stars given are comparatively quite low as compared to men on any e-commerce platform.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D40%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D40%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/0686679127bfeecbc4ae22f8aed1f2be/href">https://medium.com/media/0686679127bfeecbc4ae22f8aed1f2be/href</a></iframe><p>From the above diagram, a similar observation as that of average no. of 5 stars has been observed here as well.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D42%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D42%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/768251dafb5e4737e496af50542a21cb/href">https://medium.com/media/768251dafb5e4737e496af50542a21cb/href</a></iframe><p>There are better offers on Flipkart as compared to Amazon but it has to be noted that there are significantly less data points for Amazon.</p><h4>Model Building</h4><p>We will be training our data against following models:</p><ol><li>AdaBoost Regressor</li><li>KNN Regressor</li><li>Random Forest Regressor</li><li>Decision Tree Regressor</li></ol><p>The results are given below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D57&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D57&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/2393c0183ab8c702963c38a926d83506/href">https://medium.com/media/2393c0183ab8c702963c38a926d83506/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D58&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D58&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1affedd6dff52b7304d6f90bc08cf29/href">https://medium.com/media/f1affedd6dff52b7304d6f90bc08cf29/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D59&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D59&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/93a9aae402bb16b0b2482b3bd24f520c/href">https://medium.com/media/93a9aae402bb16b0b2482b3bd24f520c/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D60&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D60&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e309f1ed0bde5610bbb1a3484968d60a/href">https://medium.com/media/e309f1ed0bde5610bbb1a3484968d60a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttp%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D61&amp;dntp=1&amp;display_name=Jovian&amp;url=http%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D61&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/39c8b96fd3c073ec0ea1e5537f14e853/href">https://medium.com/media/39c8b96fd3c073ec0ea1e5537f14e853/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D62&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D62&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebfcb8c28f8dfae4b4b1493ac516b1cf/href">https://medium.com/media/ebfcb8c28f8dfae4b4b1493ac516b1cf/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D63%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fe-commerce-data-analysis-and-price-prediction-d6f7d%2Fv%2F1%26cellId%3D63%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fd6f7dc1bb5a24102a755b24e1bdd71d6%2Fpreview%2Fdde4937ab185411195c86a4cef3ef407&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/69c1c6e95a83f811629430372450b86c/href">https://medium.com/media/69c1c6e95a83f811629430372450b86c/href</a></iframe><p>It can be inferred that, K-Nearest Neighbours Regressor performs best amongst other algorithms, closely followed by Random Forest Regressor and Decision Trees while, AdaBoost performs the least.</p><p><strong>Inference and Conclusion</strong></p><p>Based on the thorough analysis done, it can be concluded that:</p><ol><li>About 60% of the products in the datasets are Flipkart assured/Amazon Fullfilled.</li><li>On an average, it has been observed that there are more products listed for women but 5 stars and reviews given are comparatively quite low as compared to men on any e-commerce platform.</li><li>There are better offers on Flipkart as compared to Amazon but it has to be noted that there are significantly less data points for Amazon.</li><li>K-Nearest Neighbours Regressor performs best amongst other algorithms, closely followed by Random Forest Regressor and Decision Trees while, AdaBoost performs the least.</li></ol><p><strong>References and future work</strong></p><p>All the useful links are listed below:</p><ol><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fcompetitions%2Fsa2022%2Fdata">https://www.kaggle.com/competitions/sa2022/data</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.ibef.org%2Findustry%2Fecommerce">https://www.ibef.org/industry/ecommerce</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fplotly.com%2F">https://plotly.com/</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fscikit-learn.org%2Fstable%2F">https://scikit-learn.org/stable/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8af34e7fb31a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Scientist Job Salaries Analysis]]></title>
            <link>https://medium.com/@nikhilpurao1998/data-scientist-job-salaries-analysis-f153717e2dbf?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f153717e2dbf</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 08:35:20 GMT</pubDate>
            <atom:updated>2022-09-08T10:34:56.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*LPQ8JLu8YIsDcnSem7O_4g.png" /><figcaption>Scaled map of Data Scientists Salaries across the world</figcaption></figure><p>Data Science and Machine Learning are increasingly gaining popularity in various fields such as Sports, Art, Space, medicine, healthcare and many more. It would be insightful to have a look at the salaries and current employment status of these data scientist across various places around the world.</p><p>The dataset was downloaded from kaggle (link given below) and we will be making an exploratory analysis of the data, visualise it. <a href="https://www.kaggle.com/datasets/ruchi798/data-science-job-salaries">https://www.kaggle.com/datasets/ruchi798/data-science-job-salaries</a></p><p>The dataset is divided based on Experience level as follows:</p><ol><li>EN: Entry Level</li><li>MI: Mid Level</li><li>SE: Senior Level</li><li>EX: Executive Level</li></ol><p>The dataset is divided based on Employment types as follows:</p><ol><li>FT: Full Time</li><li>PT: Part Time</li><li>CT: Contract basis</li><li>FL: Freelancer</li></ol><p>The dataset is divided based on Company size as follows:</p><ol><li>S: Small</li><li>M: Medium</li><li>L: Large</li></ol><h4>Exploratory Analysis and Visualization</h4><p>In this section, we will be doing exploratory data analysis and visualization of given dataset. Following items are on the agenda:</p><ol><li>Distribution of Experience level</li><li>Distribution of Work type</li><li>Comparing salaries of Data scientist jobs based on Experience level</li><li>Comparing salaries of Data scientist jobs based on Employment type</li><li>Comparing salaries based on experience level and Size of company</li><li>Comparing Data scientist salaries across the world</li><li>Average salary as a function of currency</li><li>Average Salary as a function of location</li><li>Top 10 Data Science job positions</li><li>Remote work status as function of time</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D29%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D29%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc50d419aa5957ddc56c3f733bd1618f/href">https://medium.com/media/cc50d419aa5957ddc56c3f733bd1618f/href</a></iframe><p>In the dataset 14.5% members are freshers while most quota is filled by Senior Engineers at 46.1%.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D32%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D32%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef9ed1844663e557adc69c896b9a3021/href">https://medium.com/media/ef9ed1844663e557adc69c896b9a3021/href</a></iframe><p>During the period 2020–2022, 62.8% of members have shifted to work from home modalities owing to Covid — 19 crisis. Later, we will see trend shifting back to the normalcy.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D38%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D38%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f053d43545e17aec6272081fe015b091/href">https://medium.com/media/f053d43545e17aec6272081fe015b091/href</a></iframe><p>Naturally, it can be seen that more the experience, better you get paid for it. However, at highest executive level, the salaries various much more as compared to other levels.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D41%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D41%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0890708d132fbe10930e909b8e25718/href">https://medium.com/media/a0890708d132fbe10930e909b8e25718/href</a></iframe><p>It seems contract based jobs earn the most out of all the type. Although the variation in their pay scale is also too high. An interesting observation is that freelancers earn more than part timers but variation in their pay scales almost looks proportional.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D44%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D44%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/527a1ad9d7182bd0af2a0243ad2590b5/href">https://medium.com/media/527a1ad9d7182bd0af2a0243ad2590b5/href</a></iframe><p>Adding a hue ‘company size’ for the previous ‘experience level’ vs ‘salary’ graph reveals more information. Senior levels jobs salaries on an average coincides with Executive level salaries. Moreover, on an average senior levels jobs salaries of small companies almost coincide with executive level salaries of respective company size.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D47%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D47%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/afbb67ab8cc1127cf49e868542e14410/href">https://medium.com/media/afbb67ab8cc1127cf49e868542e14410/href</a></iframe><p>By summing the salaries column we end up with a very skewed data towards USA. This might be because of various factors like most data scientist jobs being created in USA, the data being mostly collected in US, or the data collection form might be in English and this from might have been circulated in non-English speaking countries. However, in order to linearize the data, we will take a log10 scale on salaries column and this scaled values are passed for drawing the colors of the map.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D49%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D49%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c98612bc5faa98fa2450872abe010d60/href">https://medium.com/media/c98612bc5faa98fa2450872abe010d60/href</a></iframe><p>The sum of salaries might not be a correct measure for comparison as the entries in a particular country might be more than other. So we plot the mean keeping the log10 scale. This gives a much better idea of salaries across the world.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D51%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D51%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/2de0ea64053157dc45de2565389efa81/href">https://medium.com/media/2de0ea64053157dc45de2565389efa81/href</a></iframe><p>It can be observed that majority of data science jobs are in United States of America (US) and it also has highest paying jobs. Canada (CA), Japan (JP), Germany (DE), United Kingdom (GB), Spain (ES), France (FR), Greece (GR) and India (IN) follows in terms of highest job salaries and number of jobs (except Japan) in that order respectively.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D54%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D54%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee39a50d4e8cb3753c9cb6895157c4ba/href">https://medium.com/media/ee39a50d4e8cb3753c9cb6895157c4ba/href</a></iframe><p>Taking average salaries as a function of currency reveals that people earn most in USD, followed by Swiss franc and Singapore dollar. This graph is heavily influenced by the value of a particular currency as most currencies on the left hand side of graph have relatively high value against USD.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D57%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D57%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8cb4febb8ddd5224e1090aa6b509c01/href">https://medium.com/media/d8cb4febb8ddd5224e1090aa6b509c01/href</a></iframe><p>The location of the company also plays a vital role in determining the mean salaries. The top 10 countries in terms of average salaries are plotted.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D60%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D60%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0da16f5874a265776575ec8de2dce14/href">https://medium.com/media/a0da16f5874a265776575ec8de2dce14/href</a></iframe><p>It can be observed that Data Scientist is the most common job title followed by Data Engineers and Data Analysts respectively.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D63%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fdata-science-job-salaries-analysis%2Fv%2F4%26cellId%3D63%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fcf03193b2e91464c9a441f1d28cda9be%2Fpreview%2F47842795413448bc884deb95812f7933&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/31736892a00028671fb0528c5513a82b/href">https://medium.com/media/31736892a00028671fb0528c5513a82b/href</a></iframe><p>Due to the Covid — 19 crisis, most jobs were shifted to Work from home modality, however as the vaccines started rolling out, everything starts returning to the normalcy.</p><h4>Inferences and Conclusion</h4><p>A detailed data analysis is done for the given dataset of Data Science Job Salaries. It can be concluded that:</p><ol><li>Data Science is one the most popular and emerging field in almost all industries such as Healthcare, Sports, Art, etc.</li><li>The variation of average salary of data scientists across the world are explored.</li><li>The variation of salaries across type of employment such as Contract basis, Full-time, etc. is very crucial.</li><li>The variation of salaries as you gain experience is a rising curve.</li><li>Owing to the Covid — 19 crisis, the work environment was shifted to Work from Home and back to normalcy as the time passed.</li></ol><h4>References and Future Work</h4><p>All the useful link are listed below:</p><ol><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Fruchi798%2Fdata-science-job-salaries">https://www.kaggle.com/datasets/ruchi798/data-science-job-salaries</a></li><li><a href="https://jovian.ai/">https://jovian.ai/</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fplotly.com%2Fpython%2Fchoropleth-maps%2F">https://plotly.com/python/choropleth-maps/</a></li><li><a href="https://jovian.ai/outlink?url=https%3A%2F%2Fplotly.com%2F">https://plotly.com/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f153717e2dbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NIFTY 500 Data Analysis and Data Visualization]]></title>
            <link>https://medium.com/@nikhilpurao1998/nifty-500-data-analysis-and-data-visualization-a4e6d6c5b7ea?source=rss-2261f56a1efa------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4e6d6c5b7ea</guid>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[jovian-ml]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Nikhil Purao]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 18:26:45 GMT</pubDate>
            <atom:updated>2022-08-08T18:26:45.869Z</atom:updated>
            <content:encoded><![CDATA[<p>The dataset used is taken from the open datasets available on Kaggle (Link given below). An Exploratory analysis is performed on the dataset and few interesting observations and inferences are made in this post. <a href="https://jovian.ai/outlink?url=https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Fiamsouravbanerjee%2Fnifty500-stocks-dataset">https://www.kaggle.com/datasets/iamsouravbanerjee/nifty500-stocks-dataset</a></p><p>NIFTY 500 is stock market index of the Indian stock market and contains top 500 companies listed in National Stock Exchange (NSE).</p><p>This data is obtained for NIFTY 500 index and dated 1 July 2022. Based on the data, I will be making following Exploratory Analysis and Visualization:</p><p>In this section, we will be:</p><ol><li>Plotting top 10 gainers of the day</li><li>Plotting top 10 losers of the day</li><li>Plotting top 10 gainers of the month</li><li>Plotting top 10 losers of the month</li></ol><p>Having a look at top 10 gainers of the day:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D35%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D35%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4652c6eed9e5a392937ee463ad4d37f2/href">https://medium.com/media/4652c6eed9e5a392937ee463ad4d37f2/href</a></iframe><p>Here we can make an inference that ‘Muthoot Finance Ltd.’ is the top gainer today followed by Mahindra Holidays &amp; Resorts India Ltd. and Jubilant Foodworks Ltd..</p><p>Having a look at top 10 losers of the day:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D38%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D38%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e12b835df26b5131e3608b457c1d68e/href">https://medium.com/media/6e12b835df26b5131e3608b457c1d68e/href</a></iframe><p>We can make an inference that top 3 losers today are of companies that deal in Crude Oil and refinery products.</p><p>Top 10 Gainers of the month:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D41%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D41%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eed9532a4a650f763536d3f68a362bf/href">https://medium.com/media/4eed9532a4a650f763536d3f68a362bf/href</a></iframe><p>We can make an inference that ‘Asahi India Glass Ltd.’ &amp; ‘Adani Transmission Ltd.’ have gained over 20% in a month.</p><p>Top 10 Losers of the month:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D44%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D44%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0ade87c7f90ab8425bc0662ecac496f/href">https://medium.com/media/d0ade87c7f90ab8425bc0662ecac496f/href</a></iframe><p>We can infer that ‘AU Small Finance Bank Ltd.’ &amp; ‘Brightcom Group Ltd.’ have lost over 50% in the last month.</p><p>Now, we will be looking at the few of the interesting questions and answer them:</p><p>In this section, we will be analysing the data and answer the following questions:</p><ol><li>What sectors in NIFTY 500 have the largest share volume ?</li><li>Does the share volume directly translates to value ?</li><li>How many stocks had a major breakout in a span of a year ?</li><li>How many companies in each sector ? Does more number of companies in a sector indicate more value ?</li></ol><p>Q1: What sectors in NIFTY 500 have the largest share volume ?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D51%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D51%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d2ac6dc5828bf4c1b4921921853ba04/href">https://medium.com/media/9d2ac6dc5828bf4c1b4921921853ba04/href</a></iframe><p>From the figure, it can be seen that Financial Services and Oil Gas &amp; Consumable Fuels contribute to the largest share volume in NIFTY 500 index.</p><p>Q2: Does the share volume directly translates to value ?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D54%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D54%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec5fbf0e200b701e487cee0e8a209038/href">https://medium.com/media/ec5fbf0e200b701e487cee0e8a209038/href</a></iframe><p>We can clearly see that, even though Financial Services sector is the major contributor in share volume but Oil Gas &amp; Consumable Fuels is valued at much greater. Also share volume of ‘IT’ is not as much as Metals &amp; Mining but it is valued higher than the later.</p><p>Q3: How many stocks had a major breakout in a span of a year ?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D57%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D57%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a72253140dde6d58c409c59633564ab5/href">https://medium.com/media/a72253140dde6d58c409c59633564ab5/href</a></iframe><p>We can infer that ‘Gujarat Flourochemicals Ltd.’ &amp; ‘Trident Ltd.’ have grown over 130% in an year. It can be seen in ‘365 Day Percentage Change’ of the above data frame.</p><p>Q4: How many companies in each sector ? Does more number of companies in a sector indicate more value ?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ai%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D60%26hideInput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ai%2Fnikhilpurao1998%2Fnifty500-data-analysis%2Fv%2F33%26cellId%3D60%26hideInput%3Dtrue&amp;image=https%3A%2F%2Fapi.jovian.ai%2Fapi%2Fgist%2Fec06c76d91564151800aae2d74d6e118%2Fpreview%2F81de7e4579d54fceb9841422c08d9c38&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6886621c00f67a595b9841375a5e95e9/href">https://medium.com/media/6886621c00f67a595b9841375a5e95e9/href</a></iframe><p>As we can see there are more number of companies in ‘Financial Services’ and it translates to both ‘share volume’ as well as ‘Value’ but ‘Oil Gas &amp; Consumable Fuels’ have relatively low number of companies but they contribute largely in both ‘share volume’ &amp; ‘Value’ while opposite is the case with ‘Healthcare’ sector.</p><h3>Inferences and Conclusion</h3><p>It can be summarized that:</p><ol><li>Financial Services and Oil Gas &amp; Consumable Fuels contribute to the largest share volume in NIFTY 500 index.</li><li>Even though Financial Services sector is the major contributor in share volume but Oil Gas &amp; Consumable Fuels is valued at much greater. Also share volume of ‘IT’ is not as much as Metals &amp; Mining but it is valued higher than the later.</li><li>We can infer that ‘Gujarat Flourochemicals Ltd.’ &amp; ‘Trident Ltd.’ have grown over 130% in an year. It can be seen in ‘365 Day Percentage Change’ of the above data frame.</li><li>There are more number of companies in ‘Financial Services’ and it translates to both ‘share volume’ as well as ‘Value’ but ‘Oil Gas &amp; Consumable Fuels’ have relatively low number of companies but they contribute largely in both ‘share volume’ &amp; ‘Value’ while opposite is the case with ‘Healthcare’ sector.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4e6d6c5b7ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>