<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/real-time-codebase-indexing-from-source-files-to-searchable-context-xgdncctfx" -->

---
title: Real-Time Codebase Indexing: From Source Files to...
description: CocoIndex is an open-source tool that transforms codebases into continuously updated vector indexes using filesystem monitoring, Tree-sitter parsing, and...
canonical: https://daily.dev/posts/real-time-codebase-indexing-from-source-files-to-searchable-context-xgdncctfx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Real-Time Codebase Indexing: From Source Files to Searchable Context | daily.dev
og:description: CocoIndex is an open-source tool that transforms codebases into continuously updated vector indexes using filesystem monitoring, Tree-sitter parsing, and...
og:url: https://daily.dev/posts/real-time-codebase-indexing-from-source-files-to-searchable-context-xgdncctfx
og:image: https://api.daily.dev/og/posts/xGdNCCTFx.png
og:image:alt: Real-Time Codebase Indexing: From Source Files to Searchable Context
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Real-Time Codebase Indexing: From Source Files to Searchable Context

**[LJ](https://daily.dev/sources/l7mboiqmczrbqr416c981)** · [@badmonster0](https://daily.dev/badmonster0) · 3 min read · 2 upvotes · 0 comments

## Summary

CocoIndex is an open-source tool that transforms codebases into continuously updated vector indexes using filesystem monitoring, Tree-sitter parsing, and Postgres pgvector. The system reads source files, detects languages, splits code into semantic chunks, generates embeddings, and stores them in a searchable database. This enables real-time semantic search, AI agent context retrieval, code review automation, and infrastructure analysis without expensive re-indexing. The five-stage pipeline handles file reading, language detection, recursive splitting, embedding generation, and Postgres export with vector indexing.

## Content

Project is open sourced - [https://github.com/cocoindex-io/realtime-codebase-indexing
](https://github.com/cocoindex-io/realtime-codebase-indexing)

Modern teams rely on AI coding agents, semantic search, and automated reviews, but most workflows still treat the codebase as static text blobs instead of a rich, structured knowledge graph. This creates brittle context windows, stale embeddings, and expensive full re-indexing jobs whenever the code changes.

CocoIndex addresses this by turning your repository into a continuously updated vector index, built directly from the filesystem, parsed with Tree-sitter, and exposed via SQL and Postgres’ pgvector. The result is a real-time semantic layer over your codebase that can drive agents, editors, and internal tools without constantly re-plumbing pipelines.

The flow is logically split into five stages:

![image](https://media.daily.dev/image/upload/s--S4LAt_q6--/f_auto/v1768634235/ugc/content_6abdee69-b51e-4fc4-a2e1-442f9e186514?_a=BAMAMiiu0)

​

- Read code files from the local filesystem using a LocalFile source.
- Derive language from file extensions so Tree-sitter can parse correctly.
- Recursively split code into semantic chunks with SplitRecursively.
- Generate dense embeddings per chunk with a SentenceTransformer model.
- Export everything into Postgres with a vector index on the embedding column

```
@cocoindex.flow_def(name="CodeEmbedding")
def code_embedding_flow(
    flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataScope
) -> None:
    """
    Define an example flow that embeds files into a vector database.
    """
    data_scope["files"] = flow_builder.add_source(
        cocoindex.sources.LocalFile(
            path=os.path.join("..", ".."),
            included_patterns=["*.py", "*.rs", "*.toml", "*.md", "*.mdx"],
            excluded_patterns=["**/.*", "target", "**/node_modules"],
        )
    )
    code_embeddings = data_scope.add_collector()

    with data_scope["files"].row() as file:
        file["language"] = file["filename"].transform(
            cocoindex.functions.DetectProgrammingLanguage()
        )
        file["chunks"] = file["content"].transform(
            cocoindex.functions.SplitRecursively(),
            language=file["language"],
            chunk_size=1000,
            min_chunk_size=300,
            chunk_overlap=300,
        )
        with file["chunks"].row() as chunk:
            chunk["embedding"] = chunk["text"].call(code_to_embedding)
            code_embeddings.collect(
                filename=file["filename"],
                location=chunk["location"],
                code=chunk["text"],
                embedding=chunk["embedding"],
                start=chunk["start"],
                end=chunk["end"],
            )

    code_embeddings.export(
        "code_embeddings",
        cocoindex.targets.Postgres(),
        primary_key_fields=["filename", "location"],
        vector_indexes=[
            cocoindex.VectorIndexDef(
                field_name="embedding",
                metric=cocoindex.VectorSimilarityMetric.COSINE_SIMILARITY,
            )
        ],
    )
     
```

## Real-world use cases unlocked
Once a codebase is indexed this way, it becomes a substrate for an entire ecosystem of tooling.

- Semantic code context for AI coding agents (Claude, Codex, Gemini CLI, etc.), where each tool can pull high-precision context windows tailored to current edits or tasks.

- MCP-style integrations for editors like Cursor, Windsurf, and VSCode, enabling offline or self-hosted semantic search and navigation.

- Context-aware code search and natural language retrieval, letting developers ask “Where do we validate OAuth tokens?” instead of guessing filenames.

- AI-powered code review and PR summarization, drawing from related chunks and design areas, not just the diff.

- Automated refactoring and large-scale migrations that need to understand usage patterns across the entire repository.

- SRE workflows that index infrastructure-as-code, deployment scripts, and config files for fast incident root cause and blast-radius analysis.

Continuous generation of design documentation that stays in sync with implementation by querying the index and synthesizing higher-level artifacts.
​

## Similar posts on daily.dev

- [How Cursor Actually Indexes Your Codebase](https://daily.dev/posts/how-cursor-actually-indexes-your-codebase-kpxwbywm2) · Towards Data Science · 1 upvotes · 0 comments
- [Codebase Indexing Is Back in Kilo Code](https://daily.dev/posts/codebase-indexing-is-back-in-kilo-code-v6xslrcd1) · Kilo Blog · 0 upvotes · 0 comments
- [Building a RAG Pipeline for Semantic Code Search: A Developer Diary and Field Notes](https://daily.dev/posts/building-a-rag-pipeline-for-semantic-code-search-a-developer-diary-and-field-notes-kzctcie8s) · JetBrains · 15 upvotes · 2 comments
- [Securely indexing large codebases](https://daily.dev/posts/securely-indexing-large-codebases-sp81wdvwd) · Cursor · 1 upvotes · 1 comments

---

Tags: [#embeddings](https://daily.dev/tags/embeddings), [#postgresql](https://daily.dev/tags/postgresql), [#tree-sitter](https://daily.dev/tags/tree-sitter), [#vector-search](https://daily.dev/tags/vector-search)

[View this post on daily.dev](https://daily.dev/posts/real-time-codebase-indexing-from-source-files-to-searchable-context-xgdncctfx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/real-time-codebase-indexing-from-source-files-to-searchable-context-xgdncctfx","headline":"Real-Time Codebase Indexing: From Source Files to Searchable Context","text":"CocoIndex is an open-source tool that transforms codebases into continuously updated vector indexes using filesystem monitoring, Tree-sitter parsing, and Postgres pgvector. The system reads source files, detects languages, splits code into semantic chunks, generates embeddings, and stores them in a searchable database. This enables real-time semantic search, AI agent context retrieval, code review automation, and infrastructure analysis without expensive re-indexing. The five-stage pipeline handles file reading, language detection, recursive splitting, embedding generation, and Postgres export with vector indexing.","url":"https://daily.dev/posts/real-time-codebase-indexing-from-source-files-to-searchable-context-xgdncctfx","datePublished":"2026-01-17T07:21:05.981Z","dateModified":"2026-11-12T02:13:12.705Z","author":{"@type":"Person","name":"LJ","url":"https://daily.dev/badmonster0","image":"https://avatars.githubusercontent.com/u/1772842?v=4","description":"data for ai","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":1450}},"image":"https://media.daily.dev/image/upload/s--PbwMpql3--/f_auto/v1768634468/posts/xGdNCCTFx?_a=BAMAMiiu0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/sources/l7mboiqmczrbqr416c981","name":"LJ"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"LJ","item":"https://daily.dev/sources/l7mboiqmczrbqr416c981"},{"@type":"ListItem","position":3,"name":"Real-Time Codebase Indexing: From Source Files to Searchable Context"}]}
```

