Build a Local Markdown Search Tool with ChatGPT and SQLite FTS5
This tutorial uses ChatGPT to create a small local search tool for Markdown notes. It builds a SQLite FTS5 index and returns the original path, one-based line number and exact source line for each result. The goal is a verifiable lexical search, without embeddings, an external search service or model calls when you query the finished tool.
Prepare a disposable notes collection
You need Python 3 with SQLite FTS5 support and a new practice directory. Attach only fictional note examples to ChatGPT. Keep the source notes unchanged and choose a database filename that does not already exist. If FTS5 is unavailable in your Python build, stop and resolve that environment requirement rather than substituting a different search engine while claiming the same behavior.
1. Specify document matching and source-line output
Request search_notes.py exposing build(notes, database) and search(database, query). Ask it to index regular .md files recursively, skip symbolic links, refuse an existing database path and query the completed index through a read-only connection.
Define the search contract precisely: a matching document contains all query words. Within those documents, return each source line containing any query word. Sort results by relative path and line number. Blank or punctuation-only searches return an empty list. These rules avoid confusing document selection with the lines chosen for display.
2. Review SQL parameters and FTS syntax separately
Parameterized SQL protects the surrounding SQL statement, but the value supplied to MATCH still has FTS query syntax. An operator-looking word such as OR should be treated as a literal search token in this tool, not as permission to broaden the query.
Inspect how the generated implementation extracts words, quotes each literal token and joins the document expression with AND. Check that its line expression follows the separate any-word rule. SQLite’s FTS5 reference documents quoted strings and Boolean operators; do not treat successful SQL parameter binding as proof that these search semantics are correct.
3. Build the index and compare results with the notes
Save and read the full returned source. From your practice directory, use the demonstrated interface with new output names:
python3 search_notes.py build start/notes notes-index.sqlite
python3 search_notes.py search notes-index.sqlite "backup checksum"Use the actual source-directory path in your copy. In the recorded fixture, the first note contributes its matching heading and sentence, and the workflow note contributes its matching line. A note about SQLite alone must not appear. Open each returned Markdown file and count its physical lines from one to verify both the line number and exact text.
4. Test a fresh note and awkward queries
Try a word that looks like an operator and a punctuation-only query. Neither should accidentally return the full collection. Add a new fictional note containing both backup and checksum, then build a separate index under a new filename. The new matching line should appear in that index’s results. Reusing an existing database filename should fail rather than silently replace it.
Compare the original note bytes before and after indexing and search. A source index is useful only if its references still point to the expected material. Keep recoverable source copies; our 3-2-1 backup guide explains a broader approach to preserving those files.
Understand the limit
This is lexical search. It does not promise to understand synonyms, intent or conceptual similarity. Treat the index as a snapshot: after note changes, create and check a fresh index. Source-line references make a result easier to verify, but they do not make an outdated index current automatically.
Find related source-checked lessons in the tutorial library.
James Kennedy is a writer and product researcher at Drives Hero with a background in IT administration and consulting. He has hands-on experience with storage, networking, and system performance, and regularly improves and optimizes his home networking setup.


