<?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 Satish Shanmugam Karunakaran on Medium]]></title>
        <description><![CDATA[Stories by Satish Shanmugam Karunakaran on Medium]]></description>
        <link>https://medium.com/@shsatish?source=rss-7a26fd32854a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BUQn2Eg76h6SCBhO.jpg</url>
            <title>Stories by Satish Shanmugam Karunakaran on Medium</title>
            <link>https://medium.com/@shsatish?source=rss-7a26fd32854a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:32:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shsatish/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[A Practical Journey to compare Knowledge Graph RAG vs Vector RAG]]></title>
            <link>https://medium.com/@shsatish/a-practical-journey-to-compare-knowledge-graph-rag-vs-vector-rag-2c57b6c00587?source=rss-7a26fd32854a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c57b6c00587</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Satish Shanmugam Karunakaran]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 19:07:13 GMT</pubDate>
            <atom:updated>2026-10-27T02:41:59.884Z</atom:updated>
            <content:encoded><![CDATA[<p><em>What two retail experiments reveal about completeness, speed, and LLM token efficiency</em></p><p>A practical experiment using Python, Apache Jena Fuseki, Qdrant, OpenAI, and Streamlit</p><h3>Why this experiment matters</h3><p>Retrieval-augmented generation is often introduced as a simple recipe: embed data, retrieve the nearest chunks, and let an LLM answer.</p><p>That works well for semantic discovery. Yet many business questions are not asking for similar text. They ask for an exact set of connected records: every supplier in a category, every store selling a supplier’s products or every order linked to a returned item.</p><p>My motivation was therefore narrower and testable:</p><p>when a question requires complete relationship traversal, can structured RDF retrieval return a more complete answer with less LLM context than basic vector Top-K retrieval? I built two pipelines from the same 12 retail CSV files and compared answer correctness, time, and OpenAI API token usage.</p><p>The objective was not to prove that graph databases always win. It was to observe the trade-off, make the experiment reproducible, and formulate an architecture-selection rule called ASC: Accuracy first, Speed second, Cost third.</p><h3>What I observed across experiments</h3><p>Both tests used gpt-4o-mini for answer generation and text-embedding-3-small for vector embeddings. Apache Jena Fuseki held 52,394 RDF triples. Qdrant held 5,360 vector records. Both answer routes were available within one Streamlit application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*OeXw-UNu8CDNbQMyDR3KuQ.png" /></figure><p>Question 1: “Which suppliers provide electronics products?” The source CSV ground truth contained nine suppliers. At K=10, Vector RAG returned only four; at K=50 it returned seven. Graph RAG returned all nine.</p><p>Question 2: “What are the products and store information for ValueElectronics, and only mention the stores?” The application’s intended answer was store names. Joining the source products, order_items, orders, and stores files yielded ten distinct stores where the supplier’s products were sold. In the screenshot, Vector RAG listed nine stores; Graph RAG listed all ten. Hamburg Harbor was missing from the vector answer.</p><p>In Q1, Graph RAG used 72.7% fewer tokens than Vector K=50. In Q2, it used 71.4% fewer tokens and was approximately 23.2% faster. These results are observed single runs, not statistical performance guarantees.</p><h3>Experimental Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y8xE7s2qhEFX3D_sJ9XUOA.png" /><figcaption>Setup and Measurement</figcaption></figure><p>To conduct this experiment, I built a local RAG benchmarking environment using Python, Apache Jena Fuseki, Qdrant, Streamlit, and OpenAI. I used a retail dataset as the common data source for both approaches. Using Python and Pandas, I transformed the CSV files into an RDF Knowledge Graph (Turtle format) and loaded it into Apache Jena Fuseki.</p><p>In parallel, I converted the same dataset into vector embeddings and stored them in Qdrant. Both databases were deployed locally using Docker. I then developed a Streamlit application to submit identical natural-language questions to Graph RAG and Vector RAG, comparing their answer accuracy, response time, and LLM token consumption. For Vector RAG, I also evaluated different retrieval configurations (Top-K = 10 and Top-K = 50) to understand their impact on performance and token efficiency.</p><p>The complete setup instructions, Docker configurations, and Python scripts are available in my GitHub repository:</p><p><a href="https://github.com/shsatish/kg-Rag-Benchmark">https://github.com/shsatish/kg-Rag-Benchmark</a></p><h3>The observed system and its data</h3><p>The implementation used Python and Pandas to read twelve synthetic, interconnected retail datasets. RDFLib translated relational keys into RDF subject-predicate-object statements in a Turtle (.ttl) file.</p><p>The TTL was uploaded into Jena Fuseki. Separately, record text was embedded using OpenAI and stored in Qdrant. The Streamlit application offered “Ask Vector” and “Ask Knowledge Graph” routes.</p><p>One-time ingestion is important to separate from per-question inference: Qdrant ingestion generated approximately 467,214 embedding tokens and took 167.81 seconds in the original setup. The query-time tables in this article do not include that one-time indexing activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*CmkUiUt-itXr2yHEXfy69A.png" /></figure><h3>How I built and validated the two retrieval paths</h3><h3>Apache Jena and RDF</h3><p>I started the Fuseki container with Docker Compose from the rdf-atlas-jena directory, created the Retail-Data-Set dataset, generated Turtle from the CSV records using Python and RDFLib, then uploaded the TTL through the Fuseki “Add data” screen. The verification SPARQL COUNT query returned 52,394 triples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*iNTQ04WydWHNM8pkwJU99A.png" /><figcaption>The RDF generation step in the Python terminal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*3Tu4vF-7Oo0yY8juv4aN2A.png" /><figcaption>Turtle upload in Jena Fuseki</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*L_TVpWJMqVHaAd9MkIGo-Q.png" /><figcaption>SPARQL verification of the loaded triple count</figcaption></figure><h3>Qdrant and vector embeddings</h3><p>I ran Qdrant in a local Docker container, created the retail_rag_benchmark collection, and loaded 5,360 records using the text-embedding-3-small embedding model (1,536 dimensions, cosine similarity). The Qdrant dashboard confirmed the collection contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*7Mo7G89R7iKdcns921-aIw.png" /><figcaption>Qdrant ingestion script output</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*ivzEP0GZoHz5_S9TB6r4uA.png" /><figcaption>Qdrant collection populated with retail vector records</figcaption></figure><h3>First question A complete supplier list</h3><p>My first benchmark question was: “Which suppliers provide electronics products?” This sounds simple, but the word “which” implies a complete list, not a handful of approximately relevant records. I computed ground truth independently from the source CSVs by filtering the Electronics category and joining product supplier_id to suppliers supplier_id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*WvbG8ZpY086nNpcpwHV65g.png" /></figure><p>I asked exactly the same question three times: Ask Vector with Top-K 10, Ask Vector with Top-K 50, and Ask Knowledge Graph. Top-K controls the number of nearest vector records forwarded as retrieval context; it is not a guarantee that all qualifying suppliers appear in that context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*DB5UoZKXbN7KodiDkm0rqQ.png" /><figcaption>First question, Vector K=10 compared with Graph RAG.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*w6Yg-P0uyGNA4-BDfHWcPQ.png" /><figcaption>First question, Vector K=50 and Graph RAG, including token and time metrics</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*uDU7856cz3e1nACaYiH0dw.png" /><figcaption>Original side-by-side benchmark comparison</figcaption></figure><p>Increasing Top-K from 10 to 50 improved supplier recall from 44.4% to 77.8%, but token use increased from 798 to 3,738. The graph route returned the complete nine-supplier set using 1,021 tokens. The graph result included the tokens spent generating SPARQL; those 816 generation tokens were already part of the total.</p><h3>Second question Which stores sold ValueElectronics products</h3><p>For my second, more specific relationship question, I asked: “What are the products and store information for ValueElectronics, and only mention the stores?” I retained Vector Top-K=50 and compared it with Graph RAG. The screenshot records the precise prompt and configuration.</p><p>The independent CSV validation traversed supplier → products → order_items → orders → stores. ValueElectronics (supplier ID 211) supplied seven products, and matching orders reached ten distinct stores. The Graph answer listed ten stores. The Vector answer listed nine and missed Hamburg Harbor. The vector answer also included product descriptions despite the instruction to mention only stores.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*2CBido_SgwJBZVOdjcsfVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*sZXt8zGayTFyIVguUYDiWA.png" /><figcaption>Second-question answers and API token breakdown</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*MxmLELnVX_pS-ZvB2rsWyA.png" /><figcaption>Second-question latency breakdown and Streamlit comparison</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*DH9bYtjP-85rbfwFrqbZQQ.png" /></figure><p>Relative token reduction in Q2 = (4,464–1,275) / 4,464 × 100 = 71.44%. Relative end-to-end latency reduction = (10.804–8.299) / 10.804 × 100 = 23.19%. The SPARQL-generation token count (876) is already included in the 1,275 total.</p><h3>ASC — A model for deciding which retrieval architecture to use</h3><p>ASC prioritizes Accuracy, then Speed, then Cost. It is not a weighted average: a lower token count cannot compensate for an incomplete answer. Start by defining minimum correctness and maximum acceptable latency for the actual business workload. Only architectures that meet both constraints compete on cost.</p><h3>Accuracy from a task-level confusion matrix</h3><p>For each question, treat an entity as a positive if it belongs in the CSV-derived ground-truth answer. TP is a correctly named supplier or store. FN is a qualifying supplier or store omitted by the model. FP is an incorrectly added name. TN is not meaningfully established here because the universe of negative candidates was not defined; do not invent TN or report specificity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3EVEjRM_jvQ_n_5K7evz8w.png" /><figcaption>ASC DECISION MODEL</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*g0V9FN4P9o-vj-2MQ-diCQ.png" /></figure><p>*F1 assumes the supplier/store name lists in the screenshots contain no additional incorrect entity names (the observed named entries match the CSV ground truth). This is an entity-list evaluation, not a comprehensive evaluation of all narrative claims in the answers.</p><h3>Speed as end-to-end latency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*8wCzkcAcRL90EjoTtm_crQ.png" /></figure><p>For both questions, latency was measured end-to-end in the Streamlit application. In production, repeat each query enough times to report the 95th percentile (P95) and variability. The current screenshots show one observation per configuration, so it would be inaccurate to call these numbers P95.</p><h3>Cost efficiency using correctness percentage</h3><p>For this research, I define correctness as the percentage of required entities found, and cost efficiency as query-time API tokens per correctness percentage point. I chose this normalized measure rather than dividing tokens only by the absolute number of correct entities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*j6RnU00VAzV7BSWItco7wQ.png" /></figure><p>When CorrectnessPercentage is expressed on the 0–100 scale, the unit is tokens per percentage point. Lower is better, but only after accuracy and latency gates are passed. Do not confuse this with tokens per individual correct entity or actual monetary cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*YeD9jp582F3kh0HFo2skXg.png" /></figure><p>Example Q1: 3,738 / 77.78 = 48.06 tokens per accuracy point for Vector K=50; 1,021 / 100 = 10.21 for Graph RAG. Example Q2: 4,464 / 90 = 49.60 for Vector K=50; 1,275 / 100 = 12.75 for Graph RAG.</p><p>An equivalent normalized score using correctness as a fraction would be Tokens / (CorrectnessPercentage / 100), which produces values 100 times larger while retaining the same ranking. I use tokens per percentage point for readability and label the scale explicitly.</p><h3>ASC feasibility and optimization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*HtLvCqJmbIvzpyHw_efjiA.png" /></figure><p>Consider illustrative acceptance thresholds of at least 95% entity recall and at most 7 seconds observed latency. For Q1, the graph configuration meets both observed thresholds; K=10 fails accuracy and K=50 fails both accuracy and time. For Q2, Graph RAG achieves 100% recall but its 8.299-second runtime exceeds a 7-second limit; therefore neither tested Q2 candidate qualifies under that speed threshold.</p><p>This second example is important: ASC must permit the result “no qualifying architecture.” When a candidate fails accuracy, improve retrieval or switch method. When it fails latency, optimize or retest. Once candidates satisfy the requirements, select the least costly one; do not reject a solution merely because another is cheaper if that cheaper option fails accuracy.</p><h3>ASC evaluation criteria</h3><p>Your ASC model evaluates the two architectures in priority order: Accuracy → Speed → Cost Efficiency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*wUhTPr2l2xyu9uZdCMvYaQ.png" /><figcaption>Evaluation Criteria</figcaption></figure><p>Consolidated results — both experiments</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*J1rEV3-xW5ZCEQE-MMoCFQ.png" /></figure><h3>What the experiments do and do not prove</h3><p>These two tests indicate that explicit supplier–product–order–store relationships can produce more complete entity lists while passing less contextual text to the final LLM than this basic record-level vector Top-K baseline. They do not establish a universal advantage for graph technology. A metadata-filtered vector baseline, sparse/dense hybrid retrieval, a SQL-based solution, or a mixed Graph + Vector architecture could change the results.</p><p>The next stage is to test at least 15 questions spanning semantic lookup, entity traversal, multi-hop joins and aggregates, with repeated runs, independently calculated truth sets, P95 latency and actual currency cost. That will validate whether the proposed ASC selection rule generalizes beyond the two retail demonstrations.</p><p>The implementation is available in the GitHub repository: <a href="https://github.com/shsatish/kg-Rag-Benchmark.">https://github.com/shsatish/kg-Rag-Benchmark.</a> Readers can follow its README for installation, then use the same questions and thresholds for their own measurements. Do not commit OpenAI API secrets or environment files to the repository.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c57b6c00587" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>