By Paul Derrington, Jr.
CEO | Chief Engineer | Research Engineer | Editor, D-CSIL
5 min read
Key Takeaways
Your Markdown notes are only useful if you can find the one you half remember. This guide builds a local full-text search over a whole notes folder using Python's built-in sqlite3 module and SQLite's FTS5 search — ranked results, phrase and prefix search, and nothing leaves your machine. Every step was run and checked locally before publishing.

Why build an index instead of pasting notes into an AI chat?
The obvious alternative is to paste a note into ChatGPT or Claude and ask about it. That works for one note, once. It does not work for the note you wrote three years ago and half remember, because you have to find it before you can paste it — and finding it was the problem.
A local full-text index buys four things a chat window cannot: it searches every note you own at once, it ranks the results so the best match comes first, it is reproducible (the same search returns the same order every time), and it is private — your notes never leave your machine. The tradeoffs are real: it searches words, not meaning, so a note that says 'car' will not match a search for 'vehicle', and you have to re-run the indexer when you add notes. For a personal archive, that is a good trade.
Steps 1-2: Check your Python, then create the search table
Step 1 — check what you already have. You need Python 3 and nothing else: the sqlite3 module is part of Python's standard library, and SQLite is a library inside it, not a server you install or run. Run: python3 -c "import sqlite3; print(sqlite3.sqlite_version)". If it prints a version, you are ready. This guide was tested on Python 3.12.3 with SQLite 3.45.1.
Step 2 — create the index file and its table. FTS5 is SQLite's full-text search module: you make a special virtual table that keeps an inverted index of your words. Create a file called index_notes.py containing: import sqlite3, pathlib, sys — then con = sqlite3.connect('notes.db') and con.execute("CREATE VIRTUAL TABLE IF NOT EXISTS notes USING fts5(title, body, path UNINDEXED)"). The title and body columns get indexed; path is marked UNINDEXED so the file location is stored for display but not searched. Per the SQLite documentation, an FTS5 table is populated with ordinary INSERT statements, like any other table.
Steps 3-4: Load your notes, then commit and count
Step 3 — walk your notes folder and insert each file. Add to the script: for p in sorted(pathlib.Path(sys.argv[1]).rglob('*.md')): read the file as UTF-8 text, take its first line starting with '#' as the title (falling back to the file name), and run con.execute("INSERT INTO notes(title, body, path) VALUES (?,?,?)", (title, text, str(p))). Use the ? placeholders exactly as shown — the Python documentation is explicit that building queries by string formatting invites SQL injection, and placeholders avoid it. Start the script with con.execute("DELETE FROM notes") so every run rebuilds a clean index instead of piling up duplicates.
Step 4 — commit and prove it worked: con.commit(), then print con.execute("SELECT count(*) FROM notes").fetchone()[0]. Run it with: python3 index_notes.py /path/to/your/notes. The printed count should equal the number of Markdown files in that folder. If the count is wrong, nothing later will be right — fix it here, not after searching.
Steps 5-6: Search it — ranked, with phrases and prefixes
Step 5 — search with MATCH and rank. The query the SQLite FTS5 documentation uses is the pattern: SELECT title, snippet(notes, 1, '[', ']', '...', 12) FROM notes WHERE notes MATCH ? ORDER BY rank. MATCH runs the full-text query, ORDER BY rank sorts by relevance — FTS5's rank uses the BM25 scoring function, best match first — and snippet() returns a short excerpt with the matched words bracketed, so you can judge a result without opening the file. In the local test for this guide, searching 'budget' across two sample notes returned both, the budget note first, with [budget] marked in each excerpt.
Step 6 — use the query language, then check the edge cases. Wrap words in double quotes for an exact phrase: '"emergency fund"' matched only the note containing that phrase. Add a star for a prefix search: 'pass*' found the packing list through the word 'Passport'. Two limits to know before you trust it: searches are word-based, so check a search you know should hit (a word you are sure is in a note) before concluding a note is missing; and the index is a snapshot, so re-run the indexer after adding or editing notes — it takes seconds, and a stale index is the one failure mode that looks like success.
What you have, and what it is not
You now have a single file, notes.db, that can search your whole Markdown archive with ranked results, phrase queries, and prefix matching — no account, no subscription, no upload, and no server to maintain. Back up notes.db with your notes and the whole system moves to a new machine as two copied folders.
It is not a chatbot and it does not summarize. That is the point of the division of labor: the index finds the right note, every time, in milliseconds — then, if you want a summary, you paste that one note into an AI chat, knowing it is the right one. Search first, by a tool that cannot hallucinate a file path. Summarize second, only the thing you actually found.
If you just want to find a file on your own computer, this local index is enough. If you want Claude Code to pick up a decision Codex made yesterday without pasting the conversation over, that's what DejaVu is built for — a shared memory service for AI agents, where one agent saves the decision and the next one starts with it already in hand: https://dejavu.derringtoncollaborativeai.com/