<?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 Dipendra Laxmi Bahadur Chand Thakuri on Medium]]></title>
        <description><![CDATA[Stories by Dipendra Laxmi Bahadur Chand Thakuri on Medium]]></description>
        <link>https://medium.com/@dealbisac?source=rss-be3574e056bd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1vSi1hFyl77gZ8QQ6kBq_Q.jpeg</url>
            <title>Stories by Dipendra Laxmi Bahadur Chand Thakuri on Medium</title>
            <link>https://medium.com/@dealbisac?source=rss-be3574e056bd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:29:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dealbisac/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[AI Quantity Estimation Assistant — Multilingual RAG over Engineering PDFs]]></title>
            <link>https://dealbisac.medium.com/ai-quantity-estimation-assistant-multilingual-rag-over-engineering-pdfs-77a919d0f14a?source=rss-be3574e056bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/77a919d0f14a</guid>
            <dc:creator><![CDATA[Dipendra Laxmi Bahadur Chand Thakuri]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 09:27:16 GMT</pubDate>
            <atom:updated>2025-04-21T21:17:43.857Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an AI-Powered Quantity Estimation Assistant for Civil Engineering</h3><blockquote>Exploring generative AI applications beyond education, health, and services</blockquote><h3>Introduction</h3><p>After applying AI in education, healthcare, and various service industries, I recently ventured into a new domain — <strong>civil engineering</strong>. This project began with a simple yet ambitious goal: to help quantity surveyors and engineers estimate materials based on engineering guidelines and codes.</p><p>The result is a multilingual, intelligent assistant that leverages <strong>Google’s Gemini model</strong>, <strong>FAISS vector search</strong>, and <strong>PDF document parsing</strong> to interactively respond to queries about quantity estimation. Here’s a detailed breakdown of how the system works and what I learned along the way.</p><h3>Problem Statement</h3><p>Estimating construction materials, such as cement, steel, or bricks, from technical drawings and codes is a time-consuming process. Engineers and surveyors need to:</p><ul><li>Read large volumes of technical PDF documents</li><li>Extract key measurements and code-specific guidelines</li><li>Manually calculate material quantities based on standards</li><li>Translate content across multiple languages (especially in multilingual regions)</li></ul><p>These tasks are error-prone and not scalable. My aim was to automate parts of this workflow using generative AI.</p><h3>Solution: AI-Powered Quantity Estimation Assistant</h3><p>This notebook showcases how I built an intelligent assistant that:</p><ul><li>Extracts and chunks PDF content from civil engineering codes</li><li>Converts those chunks into semantic embeddings</li><li>Searches relevant content using FAISS vector indexing</li><li>Responds to user queries in any language using translation tools</li><li>Delivers precise, context-based answers with Google’s Gemini 2.0 Flash model</li></ul><p>This was a fresh experience — applying AI to <strong>engineering</strong> use cases pushed me to learn new data processing methods, especially for working with dense technical PDFs.</p><h3>Step-by-Step Breakdown</h3><h3>1. Environment Setup</h3><p>We begin by installing all the necessary libraries:</p><pre>!pip install -q google-generativeai faiss-cpu PyPDF2 langdetect deep-translator</pre><p>Next, we import libraries for PDF handling, embeddings, search, and translation. We install these essential Python libraries needed for PDF handling, embedding, translation, and working with Google’s Gemini model.</p><p><strong>Key libraries:</strong></p><ul><li>faiss-cpu: For fast similarity search using vector embeddings.</li><li>PyPDF2: For extracting text from PDF files.</li><li>google-generativeai: To use Gemini models for both embeddings and chat.</li><li>langdetect: To detect the language of user input.</li><li>deep-translator: To translate text into English (or back) using Google Translate.</li></ul><pre>import numpy as np<br>import pandas as pd<br>import os<br>import faiss<br>import PyPDF2<br>import google.generativeai as genai<br>from langdetect import detect<br>from deep_translator import GoogleTranslator</pre><h3>2. Configure Gemini API</h3><p>We securely fetch the Gemini API key using Kaggle Secrets. This enables us to use:</p><ul><li>Gemini’s embedding model to convert text into vectors</li><li>Gemini’s generative model to produce intelligent, context-aware answers</li></ul><pre>from kaggle_secrets import UserSecretsClient<br><br>GOOGLE_API_KEY = UserSecretsClient().get_secret(&quot;GOOGLE_API_KEY&quot;)<br>os.environ[&quot;GOOGLE_API_KEY&quot;] = GOOGLE_API_KEY<br>genai.configure(api_key=GOOGLE_API_KEY)<br><br>model = genai.GenerativeModel(&quot;gemini-2.0-flash&quot;)</pre><h3>3. Load and Extract PDF Content</h3><p>We read a selected PDF file and extract its entire text content using PyPDF2. Engineering documents, such as building codes or construction drawings, are usually shared in PDF format. To make them searchable and analyzable by AI, we must first convert their text into a usable format.</p><pre>pdf_path = &quot;/kaggle/input/updated-datasets/NBC_205_READY-TO-USE_DETAILING_GUIDELINE_FOR-signed.pdf&quot;</pre><p>Using PyPDF2, we extract text:</p><pre>def extract_text_from_pdf(file_path):<br>    text = &quot;&quot;<br>    with open(file_path, &quot;rb&quot;) as file:<br>        reader = PyPDF2.PdfReader(file)<br>        for page in reader.pages:<br>            text += page.extract_text()<br>    return text<br><br>full_text = extract_text_from_pdf(pdf_path)</pre><h3>4. Chunk the Text</h3><p>We split the full PDF text into overlapping segments of ~1000 characters. This enables the AI to process large documents without losing context. We divide the large extracted text into smaller overlapping chunks (e.g., 1000 characters with 200 characters overlap), so by chunking:</p><ul><li>Each piece becomes a manageable unit.</li><li>Overlap helps preserve context between sections.</li><li>These chunks can now be turned into vector embeddings for search.</li></ul><pre>def chunk_text(text, chunk_size=1000, overlap=200):<br>    chunks = []<br>    start = 0<br>    while start &lt; len(text):<br>        end = start + chunk_size<br>        chunks.append(text[start:end])<br>        start = end - overlap<br>    return chunks<br><br>chunks = chunk_text(full_text)</pre><h3>5. Generate Embeddings + Create FAISS Index</h3><p>Each text chunk is embedded using Gemini’s embedding model. Then, we store these embeddings in an FAISS index. FAISS allows us to perform <strong>semantic similarity search</strong>. Later, when the user asks a question, we’ll find the most relevant document chunks using these embeddings.</p><pre>def embed_text(text):<br>    response = genai.embed_content(<br>        model=&quot;models/embedding-001&quot;,<br>        content=text,<br>        task_type=&quot;retrieval_document&quot;<br>    )<br>    return np.array(response[&quot;embedding&quot;], dtype=np.float32).reshape(1, -1)<br><br>def create_faiss_index(chunks):<br>    dim = 768<br>    index = faiss.IndexFlatL2(dim)<br>    embeddings = [embed_text(chunk) for chunk in chunks]<br>    for emb in embeddings:<br>        index.add(emb)<br>    return index, np.vstack(embeddings)<br><br>faiss_index, chunk_embeddings = create_faiss_index(chunks)</pre><h3>6. Enable Multilingual Support</h3><p>Since civil engineers may work in regions with diverse languages, the assistant detects and translates inputs and outputs as needed. We use langdetect to detect the language of a user’s question and deep-translator to translate it to English (if needed). Another reason is that many users may prefer to ask in their native language, such as Nepali. But our AI model performs best in English, so translation ensures consistent accuracy.</p><pre>def detect_language(text):<br>    return detect(text)<br><br>def translate_text(text, target_lang):<br>    return GoogleTranslator(source=&#39;auto&#39;, target=target_lang).translate(text)</pre><h3>7. Retrieval-Augmented Gemini Pipeline</h3><p>Now comes the core retrieval logic. The assistant searches the top-k similar chunks and sends them to Gemini along with the user’s question. This is the core Retrieval-Augmented Generation (RAG) process. It combines search and generation to create <strong>highly relevant, context-aware answers</strong>. In this process, we</p><ol><li>Embed the user’s question.</li><li>Search the FAISS index to get the top-k similar text chunks.</li><li>Pass the question and context to Gemini’s chat model.</li><li>Get the answer.</li><li>Optionally translate it back to the original language.</li></ol><pre>def search_similar_chunks(query, chunks, index, chunk_embeddings, k=3):<br>    query_vector = embed_text(query)<br>    D, I = index.search(query_vector, k)<br>    return [chunks[i] for i in I[0]]<br><br>def generate_gemini_response(query, context_chunks):  <br>    prompt = &quot;You are a quantity surveyor assistant. Use the following context to answer:\n\n&quot;<br>    for i, chunk in enumerate(context_chunks):<br>        prompt += f&quot;[Context {i+1}]: {chunk}\n\n&quot;<br>    prompt += f&quot;Question: {query}\nAnswer:&quot;<br>    response = model.generate_content(prompt)<br>    return response.text</pre><h3>8. Test the Assistant</h3><p><strong>What we’re doing:</strong><br> We run an example question like:</p><blockquote><em>“How much cement is expected in building one wall of house?”</em></blockquote><p>The system:</p><ul><li>Detects the language</li><li>Translates the question if needed</li><li>Finds relevant context from the PDF</li><li>Sends it to Gemini for an intelligent answer</li><li>Returns the result (in the original language if applicable)</li></ul><h3>Example Interaction: Cement Estimation</h3><p>Let’s see the assistant in action.</p><blockquote><strong>User Input:</strong></blockquote><blockquote><em>How many cements is expected in building one wall of house?</em></blockquote><pre>lang = detect_language(user_input)<br>translated_input = translate_text(user_input, &quot;en&quot;) if lang != &quot;en&quot; else user_input<br><br>top_chunks = search_similar_chunks(translated_input, chunks, faiss_index, chunk_embeddings)<br>answer = generate_gemini_response(translated_input, top_chunks)<br><br>final_answer = translate_text(answer, lang) if lang != &quot;en&quot; else answer</pre><blockquote><strong>AI Assistant Response:</strong><br> The provided context specifies cement-sand mixes but does not quantify the exact amount. You need wall dimensions, brick size, joint thickness, and mix ratio (1:4 or 1:6) to calculate total cement.</blockquote><h3>Reflections</h3><p>This project was a <strong>new frontier</strong> for me. While I had worked on generative AI solutions in <strong>education, healthcare, and service</strong> domains, civil engineering introduced fresh challenges, especially when working with long, technical documents and context-aware retrieval.</p><p>It was also rewarding to see how generative AI can assist in a traditionally manual field, offering time-saving, consistent, and multilingual support for engineers in the field.</p><h3>Final Thoughts</h3><p>The combination of semantic chunking, embedding, vector search, and Gemini’s contextual language understanding makes this system robust and scalable. With further development, such assistants can become indispensable tools in the construction and design industries.</p><p>Let’s continue pushing boundaries by applying AI where it hasn’t been traditionally used.</p><h3>Links:</h3><ol><li>Our Notebook LLM:</li></ol><p><a href="https://www.kaggle.com/code/dealbisac/capstone-project-ai-quantity-estimation-assistant">Capstone Project -AI Quantity Estimation Assistant</a></p><p>2. GitHub</p><p><a href="https://github.com/dealbisac/aiestimator">GitHub - dealbisac/aiestimator: AI Estimator Buddy - An intelligent assistant for quantity surveying from engineering PDFs</a></p><p>Collaborators:</p><ul><li><a href="https://www.kaggle.com/birenairi">https://www.kaggle.com/birenairi</a></li><li><a href="https://www.kaggle.com/mahespokhrel">https://www.kaggle.com/mahespokhrel</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77a919d0f14a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>