<?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"><channel><title><![CDATA[my blogs]]></title><description><![CDATA[my blogs]]></description><link>https://stratum.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 15:09:54 GMT</lastBuildDate><atom:link href="https://stratum.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[CodeGraph: Turning Python Code into a Searchable Graph with FalkorDB]]></title><description><![CDATA[One of the things I realized while working with codebases was that finding a function isn't necessarily the hard part. Understanding how that function…]]></description><link>https://stratum.hashnode.dev/codegraph-turning-python-code-into-a-searchable-graph-with-falkordb</link><guid isPermaLink="true">https://stratum.hashnode.dev/codegraph-turning-python-code-into-a-searchable-graph-with-falkordb</guid><dc:creator><![CDATA[Keshav Nanda]]></dc:creator><pubDate>Sun, 18 Oct 2026 12:04:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/26a124a5-21a2-4280-b35c-67728a3ccc65.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Motivation Behind Building This</h2>
<p>One of the things I realized while working with codebases was that finding a function isn't necessarily the hard part. Understanding how that function connects to everything else can be a completely different challenge.</p>
<p>For example, let's say you're exploring an unfamiliar repository and come across a function. You might understand what that particular function does, but what if you want to know which other functions call it, or what parts of the codebase might be affected if you change it?</p>
<p>You could manually go through the files and trace these relationships, but that becomes increasingly difficult as the codebase grows.</p>
<p>This made me wonder: what if we could represent these relationships as a graph and actually explore them visually, rather than having to figure everything out manually?</p>
<p>That's essentially what motivated me to build CodeGraph.</p>
<p>I thought of including this section because, irrespective of the outcome of the hackathon, in the end, I got to build something, write a blog post detailing my journey, and gain lots of experience building with FalkorDB.</p>
<p>With that, let's move on to the actual technical deep dive.</p>
<h2>What Is CodeGraph?</h2>
<p>CodeGraph is a project I built that allows developers to turn a Python codebase into a searchable graph of code relationships. (I'll mention why only Python and not other languages in the limitations section.)</p>
<h3>What Can You Do with CodeGraph?</h3>
<ol>
<li><p><strong>Visualize code:</strong> See functions, classes, and their relationships as an interactive graph.</p>
</li>
<li><p><strong>Ask questions in English:</strong> Find how functions connect, what calls what, and where something is defined.</p>
</li>
<li><p><strong>Show proof:</strong> Click a connection and see the actual source code supporting it.</p>
</li>
</ol>
<p>Rather than using an LLM to guess relationships, it builds relationships from code analysis, stores them in a graph, and distinguishes confirmed, possible, and unresolved connections.</p>
<p>More on how exactly it works down below :)</p>
<h2>Architecture</h2>
<img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/973830f3-0c44-439a-9c11-3376a7aa654d.png" alt="High-level CodeGraph architecture" style="display:block;margin:0 auto" />

<p>There are mainly 7 components in CodeGraph.</p>
<h3>1. Git</h3>
<p>Supplies the exact commit to be analyzed.</p>
<h3>2. Tree-sitter</h3>
<p>This is one of the core components of how the code is broken down. Since building relationships accurately is one of the core ideas of CodeGraph, it was important to get this right.</p>
<p>Tree-sitter is an open-source parsing library that ingests source code and turns it into a tree (similar to an Abstract Syntax Tree, or AST).</p>
<p>In simple words, its job is to break Python code into meaningful pieces.</p>
<p>For example, consider <code>payment.py</code> and <code>checkout.py</code>.</p>
<p><strong>File 1 — payment.py</strong></p>
<pre><code class="language-python">def pay(amount):
    print(amount)
</code></pre>
<p><strong>File 2 — checkout.py</strong></p>
<pre><code class="language-python">from payment import pay

def checkout():
    pay(100)
</code></pre>
<p>Tree-sitter understands that:</p>
<ul>
<li><p>There's an import: <code>from payment import pay</code>.</p>
</li>
<li><p>There's a function named <code>checkout</code>.</p>
</li>
<li><p>Inside that function, there's a call to something named <code>pay</code>.</p>
</li>
<li><p>That call occurs at a particular line in the file.</p>
</li>
</ul>
<p>It organizes these discoveries into a tree like the one below:</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/ac6cc19f-017f-47ee-9a65-01b37bf89674.png" alt="Tree-sitter syntax tree diagram" /></p>
<p>Tree-sitter realizes that <code>pay(100)</code> is a function call, but it doesn't automatically know which <code>pay()</code> function that name refers to.</p>
<p>There could be ten different functions named <code>pay</code> across your repository. This leads us to the second key component — SCIP.</p>
<h3>3. Source Code Intelligence Protocol (SCIP)</h3>
<p>Source Code Intelligence Protocol, or SCIP for short, is the standard format used for storing information about code symbols and references.</p>
<p>A semantic indexer analyzes the code and produces SCIP information that CodeGraph can use.</p>
<p>Using File 2 as an example:</p>
<p>Tree-sitter identifies that there's a call to <code>pay</code>.</p>
<p>SCIP can tell us that this reference points to the <code>pay</code> function defined in <code>payment.py</code>.</p>
<p>The diagram below should help you understand the use of SCIP.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/ddfa3d00-9acc-4207-bcc3-8f92af2f89ea.png" alt="3" /></p>
<p>In short, Tree-sitter is used to identify pieces of Python code and their structure, while SCIP carries information that helps identify which actual functions, classes, or variables those references point to.</p>
<h3>4. Graph Builder and FalkorDB</h3>
<p>This stores all the relationships built by Tree-sitter and SCIP into FalkorDB, a graph database.</p>
<p>Here, the nodes represent modules, classes, functions, methods, and other code entities, while the edges represent relationships such as defines, calls, imports, and other relationships supported by the extraction pipeline.</p>
<p>For each relationship it builds, it needs to know:</p>
<table>
<thead>
<tr>
<th>Information</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td>Source</td>
<td><code>checkout()</code></td>
</tr>
<tr>
<td>Relationship</td>
<td>Calls</td>
</tr>
<tr>
<td>Target</td>
<td><code>pay()</code></td>
</tr>
<tr>
<td>Evidence</td>
<td><code>checkout.py:4</code></td>
</tr>
<tr>
<td>Version</td>
<td>Repository + Git commit</td>
</tr>
</tbody></table>
<p>CodeGraph gives entities identities tied to their repository, commit, and names so that two different functions with the same name cannot be confused with one another.</p>
<p>FalkorDB stores the connections between them, making it useful for traversing chains of relationships.</p>
<p>For example, a graph query can conceptually ask:</p>
<p>"Starting from <code>checkout()</code>, follow call relationships up to three steps and return the functions reached."</p>
<p>FalkorDB is especially important here because following relationships is the primary operation, rather than merely searching for words in files.</p>
<h3>5. Provenance</h3>
<p>One of the things I wanted to make sure of was that CodeGraph doesn't simply show relationships and expect developers to blindly trust them.</p>
<p>This is where provenance comes in.</p>
<p>In simple words, provenance means keeping track of where a particular piece of information came from.</p>
<p>For example, let's go back to our earlier example involving checkout() and pay().</p>
<p>If CodeGraph tells us that checkout() calls pay(), it should also be able to tell us where it found that relationship.</p>
<p>This could include the source file, the line where the function call occurs, and the exact Git commit that was analyzed.</p>
<p>So rather than just showing:</p>
<p>checkout() → calls → pay()</p>
<p>CodeGraph can also provide the source evidence supporting that connection.</p>
<p>Another important thing is that not every relationship can be identified with complete certainty.</p>
<p>Sometimes, CodeGraph can identify the exact function being called. Other times, there might be multiple possible targets, or it might not be able to resolve the target at all.</p>
<p>Instead of treating all these cases as equally certain, CodeGraph keeps track of these differences.</p>
<p>After all, there's not much point in building a graph of code relationships if you can't explain where those relationships actually came from.</p>
<h3>6. Vector Retrieval</h3>
<p>If a repository has 1,000 functions and you want to find out which function handles user authentication, vector retrieval comes in handy, as rather than simple keyword matching, it works by checking the meaning of your question against the indexed code.</p>
<p>The important distinction is:</p>
<ul>
<li><p><strong>Vector retrieval:</strong> Helps locate which code might be relevant.</p>
</li>
<li><p><strong>FalkorDB:</strong> Shows how that code is actually connected.</p>
</li>
</ul>
<p>Vector retrieval cannot prove that two functions call each other.</p>
<p>Another important thing to note is that vector retrieval is not ALWAYS needed. A precise question naming two known functions can go straight to symbol lookup (Tree-sitter + SCIP) and graph traversal.</p>
<h3>7. Frontend</h3>
<p>Now that we've gone through how the relationships are identified and stored, we need a way for developers to actually interact with them.</p>
<p>This is where the frontend comes in.</p>
<p>Rather than expecting developers to write graph queries themselves, CodeGraph provides an interface where they can explore the repository and ask questions in plain English.</p>
<p>There are mainly four parts to the interface:</p>
<p>Investigate: Ask questions about the repository and explore the answers along with their supporting evidence.</p>
<p>Explore Graph: Visually explore functions, classes, and their connections. You can also select relationships to inspect them in more detail.</p>
<p>Changes &amp; Tests: Compare Git commits, investigate potentially affected code, and explore relevant test information.</p>
<p>History: Revisit previous investigations without having to start from scratch.</p>
<p>One of the things I wanted to focus on was making the graph easy to understand, even for someone who isn't familiar with graph databases.</p>
<p>The idea is fairly simple: you shouldn't have to understand how FalkorDB works internally just to figure out how two functions in your codebase are connected.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/1712f5ff-ca99-4059-a90d-e362622efe85.jpg" alt="4" /></p>
<h2>CodeGraph in Action</h2>
<p>Now that we've gone through the architecture, let's actually see how all these components come together.</p>
<p>For this, I decided to use Click, an open-source Python library used for building command-line interfaces.</p>
<p>Once the repository is ingested, CodeGraph analyzes the Python files, identifies relationships, and stores them in FalkorDB.</p>
<p>From here, I can ask questions about the codebase in plain English, and CodeGraph will try to find the relevant relationships.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/7ca276db-57a5-4e73-b420-bc64945fa40f.png" alt="5" /></p>
<p>One thing I wanted to make sure of was that CodeGraph doesn't simply give an answer and expect the developer to trust it.</p>
<p>You can click on a connection in the graph and inspect the source code supporting it.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/04c81149-12b1-4b16-8758-ecdaf4130f84.png" alt="6" /></p>
<p>This was one of the main things I wanted to achieve with CodeGraph: rather than blindly trusting an answer, developers should be able to see where the information actually came from.</p>
<h2>Git Changes &amp; Impact Analysis</h2>
<p>I wanted the ability to understand how changes to one part of a codebase might affect other parts.</p>
<p>For example, let's say you modify a function that's being called by several other functions. How would you know which parts of the codebase might be affected?</p>
<p>CodeGraph allows you to compare two Git commits and investigate the relationships surrounding the changed code.</p>
<p>Rather than just showing which lines were added or removed, it uses the graph to identify potentially affected functions and their connections.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/7d853865-ff8d-4da3-a140-a926a5f8bb8a.jpg" alt="7" /></p>
<p>Of course, this doesn't necessarily mean every connected function will break. It simply helps narrow down where a developer might want to investigate further</p>
<h2>Limitations and Architectural Hurdles</h2>
<p>While the architecture seems fairly straightforward, there were A LOT of hurdles that were fairly difficult to overcome.</p>
<ul>
<li><p>I had to make sure the system didn't allow users to ask generic and vague questions ("What day is it today?"). It should allow you to ask questions only based on the repository you ingested.</p>
</li>
<li><p>For now, it only works for Python. This is a fairly big drawback in my eyes, but this choice was made because semantic resolution is language-specific. Resolving Python imports and methods is different from resolving Java or C++ code.</p>
</li>
<li><p>Just because a function or method exists in code doesn't mean it always runs during runtime (static analysis ≠ runtime execution). This is something that hasn't really been explored much due to limited time.</p>
</li>
<li><p>Python allows programs to change certain things while they're running.</p>
<p>For example:</p>
<pre><code class="language-python">class Email:
    def send(self):
        print("Sending email")

class SMS:
    def send(self):
        print("Sending SMS")

def notify(service):
    service.send()
</code></pre>
<p><code>service.send()</code> could refer to either <code>Email.send()</code> or <code>SMS.send()</code> depending on the object passed to <code>notify()</code>. A sophisticated analyzer might be able to recognize both, but it cannot always claim that one is always called.</p>
<p>This is another fairly big limitation.</p>
</li>
</ul>
<p>Apart from these, there are a lot of other issues that could probably be more polished, like UI, performance, and much more, but certain decisions had to be made due to time restrictions.</p>
<h2>What I Learned Building with FalkorDB</h2>
<p>One of the biggest things I learned while building CodeGraph was how useful graph databases can be when dealing with information that's heavily interconnected.</p>
<p>Initially, it's easy to think of a codebase as just a collection of files, functions, and classes. But once you start looking at how these components interact with one another, representing them as a graph starts making a lot more sense.</p>
<p>FalkorDB made it possible to store these relationships and traverse connections between different parts of the codebase.</p>
<p>However, one thing I quickly realized was that building the graph itself wasn't the hardest part.</p>
<p>Making sure the relationships were actually correct was just as important.</p>
<p>After all, there's not much point in showing developers a graph if the connections themselves are inaccurate.</p>
<p>This was one of my biggest takeaways from the project: building something that gives an answer is one thing, but building something that can explain why it gave that answer is a completely different challenge.</p>
<p>Overall, working with FalkorDB gave me a much better understanding of graph databases and how they can be used to solve problems beyond traditional data storage.</p>
<h2>Conclusion</h2>
<p>Overall, I enjoyed building CodeGraph, and I hope you enjoyed reading this too :)</p>
<p>The code will be open-sourced as soon as the hackathon ends, and I hope you could learn something from this read.</p>
<p>Thanks, and have an amazing day ahead!</p>
]]></content:encoded></item><item><title><![CDATA[Stratum: A KV Store in Go]]></title><description><![CDATA[The inspiration behind this project was to revise syntax but I'm happy this matured into something far better than what I hoped for :) A key value store is…]]></description><link>https://stratum.hashnode.dev/stratum-a-kv-store-in-go</link><guid isPermaLink="true">https://stratum.hashnode.dev/stratum-a-kv-store-in-go</guid><dc:creator><![CDATA[Keshav Nanda]]></dc:creator><pubDate>Sat, 11 Jul 2026 13:56:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/80c4d2da-a7ca-4a0a-a8db-e2601c43e01f.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The inspiration behind this project was to revise syntax but I'm happy this matured into something far better than what I hoped for :)</p>
<p>A key value store is a very simple type of database. It works by initialising a continuous block of memory (like an array) of size BUCKET_SIZE.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/dddda345-f3b8-45ca-9338-ad2efb92b100.png" alt="" />
Similar to a typical database, KV store has 3 main operations:</p>
<ul>
<li><p>PUT - To insert the key and value</p>
</li>
<li><p>GET - To get the value stored at 'key'</p>
</li>
<li><p>DELETE - To delete the stored key value pair</p>
</li>
</ul>
<p>Now how do we decide which block or array to insert a key in? A naive way would be to just insert in the first block that's free. But as the size of the table grows, this becomes more inefficient as the complexity will soon approach O(n).</p>
<p>What could be a better solution? Instead of searching for an empty bucket in the table, what if you somehow got the bucket from the key itself?</p>
<p>This is where hashing comes in. You can hash the key and modulo by bucket size to get the bucket it's supposed to go to.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/8412ab5c-979e-4fe1-a5ad-6a962f1471e7.png" alt="" /></p>
<p>This method works fairly well. However, an issue is that as the buckets get more filled, collisions become more likely. Therefore, we will need a way to deal with collisions (ie, when a key value pair wants to occupy a bucket but it is already taken by another key value pair).</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/89dc1958-50ba-497d-b34d-e0f289d6dd77.png" alt="" /></p>
<p>There are multiple ways to handle collisions, but the one I'll be talking about is separate chaining. In this method, a bucket stores a linked list and each node points to the next node in the chain, which stores a key value pair. Checking if a key exists would require traversing all the nodes of the linked list.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6a51f8fc428c6df4e7cbb9e1/a2c38550-1843-4766-90d3-97ed57412d4b.png" alt="" /></p>
<p>Although this can directly be implemented, Go supports something known as dynamic slices. Meaning instead of storing them as linked lists in a bucket, you can store them like below:</p>
<pre><code class="language-plaintext">Bucket 0
[
  cat    : 50
  dog    : 75
]

Bucket 1
[
  grape  : 90
]

Bucket 2
[
  apple  : 10
  banana : 25
  orange : 30
]

Bucket 3
[
  kiwi   : 15
  mango  : 45
]
</code></pre>
<p>This is very similar to how separate chaining works, but works without the additional overhead of storing a Next Ptr for each node, thus making it more memory efficient.</p>
<p>With all this, now we're ready to implement our <code>PUT</code> function that takes a key value pair and inserts it into the table (also known as memtable as all the key value pairs are stored in memory).</p>
<p>Implementing <code>GET</code> is also fairly simple. Traverse the memtable and check if <code>entry.key == key1</code> where <code>key1</code> is the key being searched for. It's important to remember that since our implementation can store multiple KV pairs in a single bucket, you will have to use two for loops to check if the entry exists within a bucket.</p>
<p>Deletion also follows a similar approach. Search for the key, and once the key is found, remove it.</p>
<p>There's actually a fairly smart syntax that you can use here to do this, which I found very cool.</p>
<pre><code class="language-go">table[bucket] = append(table[bucket][:index], table[bucket][index+1:]...)
</code></pre>
<p>This line says that take all the entries present till index, and to that slice, append every entry after index+1. This means the element at index is deleted. The <code>…</code> after index +1 is because <code>table[bucket][index+1:]</code> returns a slice, and append expects individual elements rather than a slice. The <code>…</code> unpacks (spreads) that slice into individual arguments so append can use them.</p>
<p>With this, we are done with the three main functions of a simple KV Store :)</p>
<p>Now let's think about this further, what are some cases that we could have missed out in this implementation?</p>
<p>What would happen if the memtable is completely filled with KV pairs? At that point the very next insertion would fail. How would we prevent this?</p>
<p>The solution is to create another function that checks if the load factor (ENTRIES/BUCKET_SIZE) &gt;= 0.75. If this condition is true, meaning more than 75 percent of the memtable is full, then the memtable will have to be resized to a bigger amount.</p>
<p>The reason why we are resizing the table when it's 75 percent filled is because</p>
<ol>
<li><p>Inserting a lot of entries in one bucket makes traversal slower since each bucket now has more entries.</p>
</li>
<li><p>Maintaining a low load factor gives an average lookup time of O(1), thereby increasing performance.</p>
</li>
</ol>
<p>Increasing the bucket size would require every entry inside the memtable to be rehashed. Recollect that <code>bucket := hash(key) / BUCKET_SIZE</code>. Since bucket size has changed, we would have to traverse and rehash every key in each bucket. The following code snippet accomplishes this.</p>
<pre><code class="language-go">func resize() {
	// every entry in a bucket has to be rehashed and appended to new table
	if float64(ENTRIES)/float64(BUCKET_SIZE) &gt; 0.75 {
		NEW_BUCKET_SIZE := 2 * BUCKET_SIZE
		new_table := make([][]Entry, NEW_BUCKET_SIZE)
		for _, bucket := range table {
			for _, entry := range bucket {
				new_bucket := int(hash(entry.key) % uint64(NEW_BUCKET_SIZE)) // bucket should be int
				new_table[new_bucket] = append(new_table[new_bucket], entry)
			}
		}
		table = new_table
		BUCKET_SIZE = NEW_BUCKET_SIZE
	}
}
</code></pre>
<p>And with that, we are done with a very basic KV Store in Go :)</p>
<p>I have implemented some more advanced concepts (WAL, SSTables, etc) to take this idea further, which I will touch upon in my next blog post.</p>
<p>Thanks for reading :)</p>
<p>GitHub repo: <a href="https://github.com/0xmaster7/Stratum/">https://github.com/0xmaster7/Stratum/</a></p>
]]></content:encoded></item></channel></rss>