<?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 Siddhartha Singh Rajput on Medium]]></title>
        <description><![CDATA[Stories by Siddhartha Singh Rajput on Medium]]></description>
        <link>https://medium.com/@sidvid.rajput?source=rss-553adf7d822e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xnVtL6D-N7DJOgAu.jpg</url>
            <title>Stories by Siddhartha Singh Rajput on Medium</title>
            <link>https://medium.com/@sidvid.rajput?source=rss-553adf7d822e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:31:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sidvid.rajput/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Full-Stack Document Reader using LangChain, OpenAI, Pinecone, and Node.js (Part -1 )]]></title>
            <link>https://medium.com/@sidvid.rajput/building-a-full-stack-document-reader-using-langchain-openai-pinecone-and-node-js-part-1-cccb39a84fbc?source=rss-553adf7d822e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cccb39a84fbc</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Siddhartha Singh Rajput]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 16:18:31 GMT</pubDate>
            <atom:updated>2025-08-03T16:18:31.666Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, I’ll walk you through how I built a full-stack document reader using some of the most powerful tools in the AI ecosystem: <strong>LangChain</strong>, <strong>OpenAI</strong>, <strong>Pinecone</strong>, and <strong>Node.js</strong>. This project lets users upload a PDF and ask questions about its content — the system answers by pulling contextually relevant chunks using embeddings.</p><p>Let’s break it down step-by-step.</p><p>📦 Tech Stack Overview</p><ul><li><strong>Frontend</strong>: Custom-built React app (not covered here)</li><li><strong>PDF Parsing</strong>: pdf-parse</li><li><strong>Embedding Model</strong>: text-embedding-3-large (OpenAI)</li><li><strong>LLM</strong>: gpt-4o-mini</li><li><strong>Backend</strong>: Node.js (Express), LangChain, OpenAI API, Pinecone</li></ul><h3>🧠 Architecture</h3><p>Here’s the high-level flow:</p><ol><li>Parse and split PDF document into chunks.</li><li>Embed each chunk using OpenAI’s embedding model.</li><li>Store embeddings in Pinecone vector DB.</li><li>At query time, embed the question.</li><li>Perform similarity search in Pinecone.</li><li>Pass retrieved chunks and query to OpenAI Chat API for answer generation.</li></ol><p>📄 Step 1: PDF Ingestion &amp; Chunking<br>We use pdf-parse to read a document and split it using LangChain’s RecursiveCharacterTextSplitter.</p><pre>const pdfParse = (await import(&quot;pdf-parse&quot;)).default;<br>const pdfBuffer = readFileSync(path.resolve(&quot;book.pdf&quot;));<br>const dataForPdf = await pdfParse(pdfBuffer);<br>const pages = dataForPdf.text.split(/\f/);</pre><p>To maintain context across pages, we added a clever overlap strategy — grabbing the <strong>last 10% of the previous page</strong> and adding it to the current one:</p><pre>const getLast10Percent = (text) =&gt; {<br>  const cutoff = Math.floor(text.length * 0.1);<br>  return text.slice(-cutoff);<br>};</pre><p>✂️ Step 2: Splitting and Embedding Chunks</p><p>We create Document objects for each page, then split those into smaller pieces using LangChain:</p><pre>const splitter = new RecursiveCharacterTextSplitter({<br>  chunkSize: 1000,<br>  chunkOverlap: 200,<br>});<br>const splitDocuments = await splitter.splitDocuments(documents);<br>const embedResponse = await embeddings.embedQuery(item.pageContent);</pre><p>🧭 Step 3: Setting Up Pinecone</p><pre>const index = await connectToPinecone();<br><br>const vectors = splitDocuments.map((item, i) =&gt; ({<br>  id: `doc-${i}`,<br>  values: embedResponse,<br>  metadata: { text: item.pageContent },<br>}));<br><br>await index.upsert(vectors);</pre><p>🤖 Step 4: Answering Questions<br>When the user sends a question, we:</p><ol><li>Embed the question</li><li>Search Pinecone for relevant chunks</li><li>Send the question and chunks to the LLM for an answer.</li></ol><pre>const queryResponse = await index.query({<br>  vector: queryVector,<br>  topK: 5,<br>  includeMetadata: true,<br>});<br>const prompt = ChatPromptTemplate.fromMessages([<br>  [<br>    &quot;system&quot;,<br>    `You are given a question and several text chunks. Use only the chunks to answer.`,<br>  ],<br>  [&quot;human&quot;, &quot;{question}&quot;],<br>]);<br><br>const chain = prompt.pipe(chatLLM);<br>const minifiedResponse = await chain.invoke({<br>  input_language: &quot;English&quot;,<br>  output_language: &quot;English&quot;,<br>  chunks: answersArray,<br>  question,<br>});</pre><p>To be continued ……………..<br>let me know in comments if you want github link.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cccb39a84fbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First genAI project using React js and Langchain]]></title>
            <link>https://medium.com/@sidvid.rajput/my-first-genai-project-using-react-js-and-langchain-6985165dd97d?source=rss-553adf7d822e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6985165dd97d</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[react-js-tutorials]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Siddhartha Singh Rajput]]></dc:creator>
            <pubDate>Thu, 29 May 2025 16:15:19 GMT</pubDate>
            <atom:updated>2025-05-29T17:47:18.130Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What we are building</strong></h3><p>Jese ki ye mera pehla project hai genAI me to aaj ka tutorial beginner friendly rakhte hai.<br>Aaj hum bana rahe hai Persona Clone.<br>Hum use karne wale hai openAI k “gpt-4.1-nano” model ko.</p><h3>Lets Code</h3><p>Bina time waste kiye sabse pahle hum aate hai vs code me or vite install karte hai.<br>Vite ki installation me mai nahi jaunga kyoki ye tutorial ka motive nahi hai.<br>Sabse pahle humne do pages ready kiye hai <br>1).Home page (Jaha se user select karega usko kis k persona se chat karni hai).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hciRk7SOWaP1e-NT8TPQFg.png" /></figure><p>2).Chat page (jaha actually me user selected persona k sath chat karega)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qmq-EXMeHr7gG3l4szTcxw.png" /></figure><p>ye to baat hui basic React Js ki.<br>Ab hum aate hai basic of genAI par.</p><h3>What is Prompt</h3><p>LLMs se baat karne k liye or LLMs se wo input paane k liye jo hume chaiye , usko Prompt kehte hai.<br><em>Why it is necessary to understand the prompt….</em></p><p>Eg: Aap ek persona banane ja rahe hai or apka persona bhut rude behaviour wala hai to aap LLMs ko interact karne k liye Prompt ka hi to use karoge.Prompts k dwara hi to btaoge na k ye persona mera rude behaviour wala hai ( jese k jaya bacchan ji …)</p><p>Chailye samjhte hai k Promts kitne trah k hote hai or inko kese input me dia jata hai <br><em>There are 8 prompt engineering methods:<br>(1) Zero-Shot Learning, (2) One-Shot Learning, (3) Few-Shot Learning,<br>(4) Chain-of-Thought Prompting, (5) Iterative Prompting,<br>(6) Negative Prompting, (7) Hybrid Prompting, and<br>(8) Prompt Chaining</em></p><p>aaj hum sirf 3 promts k bare me dekhe wale hai kyoki ye beginner friendly tutorial hai.</p><p><em>(1) Zero-Shot Learning,</em></p><p><em>Learning </em>kyu bola yaha.</p><p>Learning ka yaha matlab hai LLMs ko learn karana</p><p>shot ka kya matlab hai → number of examples give<br>or Zero ka kya matlab hai, matlab LLMs ko prior koi knowledge nahi di gai seedha usko prompt de dia <br>eg : “Classify the sentiment of the following text as positive, negative, or neutral.<br>Text: I think the vacation was okay.<br>Sentiment:”</p><p>yaha par notice kareyega , LLMs ko koi prior info nahi de gai ab LLM ka jo bhi answer hoga wo uski prior knowledge k base par hi hoga.</p><p><em>(1) One-Shot Learning</em></p><p>One-shot → matlab ek example dia LLM ko or us se umeed ki ja rahi hai wo is hi example ko use kar k hume output de</p><p>eg: “Classify the sentiment of the following text as positive, negative, or neutral.<br>Text: The product is terrible.<br>Sentiment: Negative</p><p>Text: I think the vacation was okay. Sentiment:”</p><p>CODE KAHA HAI …………………..</p><p>okay okay ….enough of theory …<br>Now lets code</p><p>first install the openai library using “<em>npm install openai</em>”</p><p>Now , import the openai in your component</p><pre>import OpenAI from &quot;openai&quot;;</pre><p>Jese hi maine pahle bhi btya apko mai React JS use kar raha hu aap python bhi use kar sakte hai ya JavaScript ko bhi.<br>Maine jo prompting use ki hai wo few shots use ki hai.</p><p>Ab few shots me hum kuch examples de dete hai or LLM se umeed ki jati hai wo usi template ko use kar k hume answer de</p><pre>  const response = await client.responses.create({<br>        model: &quot;gpt-4.1-nano&quot;,<br>        temperature: 0.7,<br>        input: [<br>            { &quot;role&quot;: &quot;system&quot;, &quot;content&quot;: SYSTEM_PROMPT },<br>        { &quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Hey, My name is Siddhartha&quot;},<br>        { &quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;Hey Siddhartha! If you have any Typescript questions or need help with code, feel free to ask!&quot;},<br>        { &quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;What are yu doing?&quot;},<br>        { &quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;Hey Siddhartha, I’m here to help with Typescript, not here for anyother queries&quot;},<br>    <br>        ],<br>      });</pre><p>Ab maine apne LLM ko bola hai k sirf mujhe Ts k queries k bare me hi jawab dena or agar question or kuch ho to boss seedha mana kar dena.<br>Ab aate hai apne actual Project par</p><pre>import React, { useEffect, useState } from &quot;react&quot;;<br>import &quot;./scss/chat.scss&quot;;<br>import { useLocation } from &quot;react-router-dom&quot;;<br>import Mohit from &quot;../assets/mohit_kanwar.jpeg&quot;;<br>import Modiji from &quot;../assets/narendra_modi.jpeg&quot;;<br>import { Input } from &quot;antd&quot;;<br>import OpenAI from &quot;openai&quot;;<br>import ButtonXP from &quot;../components/button&quot;;<br>import { MODIJIPROMPT, MOHITKANWARPROMPT } from &quot;../utils/constants&quot;;<br><br>const key = import.meta.env.VITE_OPENAI_API_KEY;<br>console.log(&quot;OpenAI Key&quot;, key);<br><br>const client = new OpenAI({ apiKey: key, dangerouslyAllowBrowser: true });<br><br>const { TextArea } = Input;<br>function Chat() {<br>  const [inputValue, setInputValue] = React.useState(&quot;&quot;);<br>  const [loading, setIsLoading] = useState(false);<br>  const [data, setData] = useState&lt;any&gt;([]);<br>  const params = useLocation();<br>  console.log(&quot;Params&quot;, params);<br>  const prompMapping = {<br>    1: {<br>      prompt: MODIJIPROMPT,<br>      avatar: Modiji,<br>    },<br>    2: { prompt: MOHITKANWARPROMPT, avatar: Mohit },<br>  };<br><br>  console.log(&quot;DATA&quot;, data);<br>  const callOpenAi = async (updatedData: any) =&gt; {<br>    try {<br>      setIsLoading(true);<br>      const response = await client.responses.create({<br>        model: &quot;gpt-4.1-nano&quot;,<br>        temperature: 0.7,<br>        input: [<br>          {<br>            role: &quot;system&quot;,<br>            content:<br>              prompMapping?.[params?.state.selectedCard[0].id as 1 | 2]?.prompt,<br>          },<br>          { role: &quot;user&quot;, content: &quot;hey&quot; },<br>          ...(updatedData || []),<br>        ],<br>      });<br>      setData((preData: any) =&gt; [<br>        ...preData,<br>        { role: &quot;system&quot;, content: response.output_text },<br>      ]);<br>      setIsLoading(false);<br><br>      console.log(response);<br>    } catch (error) {<br>      setIsLoading(false);<br>      console.log(&quot;Error:&quot;, error);<br>    }<br>  };<br><br>  useEffect(() =&gt; {<br>    callOpenAi(data);<br>  }, []);<br><br>  return (<br>    &lt;div className=&quot;chat-container&quot;&gt;<br>      &lt;div className=&quot;message-wrapper&quot;&gt;<br>        {data.map(({ content = &quot;&quot;, role = &quot;&quot; }, index = &quot;&quot;) =&gt; (<br>          &lt;div<br>            className={`message-item-wrapper ${<br>              role === &quot;user&quot;<br>                ? &quot;message-item-wrapper-user&quot;<br>                : &quot;message-item-wrapper-system&quot;<br>            }`}<br>            key={index}<br>          &gt;<br>            &lt;div<br>              className={`message ${<br>                role === &quot;user&quot; ? &quot;user-message-type&quot; : &quot;system-message-type&quot;<br>              }`}<br>            &gt;<br>              {role === &quot;system&quot; &amp;&amp; (<br>                &lt;span className=&quot;avatar&quot;&gt;<br>                  &lt;img<br>                    width={40}<br>                    height={40}<br>                    src={<br>                      prompMapping[params.state.selectedCard[0].id as 1 | 2]<br>                        .avatar<br>                    }<br>                    alt=&quot;Avatar&quot;<br>                  /&gt;<br>                &lt;/span&gt;<br>              )}<br>              &lt;span className=&quot;content&quot;&gt;{content}&lt;/span&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br>        ))}<br>        {loading &amp;&amp; (<br>          &lt;div className=&quot;message-item-wrapper-system&quot;&gt;<br>            &lt;p className=&quot;typing-indicator&quot;&gt;Typing...&lt;/p&gt;<br>          &lt;/div&gt;<br>        )}<br>      &lt;/div&gt;<br>      &lt;div className=&quot;input-wrapper&quot;&gt;<br>        &lt;TextArea<br>          className=&quot;chat-textarea&quot;<br>          value={inputValue}<br>          onChange={(e) =&gt; setInputValue(e.target.value)}<br>          rows={3}<br>          placeholder=&quot;Type your message...&quot;<br>        /&gt;<br>        &lt;ButtonXP<br>          onClick={() =&gt; {<br>            const updatedData = [<br>              ...data,<br>              { role: &quot;user&quot;, content: inputValue },<br>            ];<br>            setData(updatedData);<br>            callOpenAi(updatedData);<br>            setInputValue(&quot;&quot;);<br>          }}<br>          text=&quot;Send&quot;<br>        /&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Chat;</pre><p>yaha par mai user se message le raha hu or us message k base par fir se LLM ko call laga raha hu wo mujhe output de raha hai or mao simple usko ui par show kara de raha hu.<br>Bus itna hi simple hai ……..<br>Baki ka gyaan agle tutorial me.</p><p>bitbucket link : <a href="https://bitbucket.org/sidd15/persona_clone/src/main/">https://bitbucket.org/sidd15/persona_clone/src/main/</a><br>website link : https://persona-clone-6qqx.vercel.app/<br>#ChaiOrCode</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6985165dd97d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>