Open Brain: The Database Core — Supabase, pgvector, and Hybrid Search
Before you start: approve the plan in Part 1. Use synthetic notes until the access checks pass; the first build does not need a bot or browser interface.
Done when: you can save a synthetic note, retrieve its original text by meaning and an exact reference, and reject an unauthorized caller.
The first useful milestone is small: save a note, search for it, and read back the original text. Supabase hosts PostgreSQL, the database that stores your notes. The pgvector extension adds support for embeddings: lists of numbers used to find related text.
Imagine saving a note that says: “Ana will send the code on Friday.” Later, you remember the task but not the wording, and search for “Who will share the script, and when?” Meaning-based search should bring back the original note even though your question uses different words. This is a fictional example, not a result from my own system.
Keyword search helps in a different situation: you remember an exact name or reference code and want to find that specific text. The tests below check both kinds of search.
The pieces that matter
Keep the original note, its source, a stable ID, and its capture time. Labels such as project and language help narrow searches. AI-generated summaries are conveniences; they should never replace the original.
The embedding model and vector column must agree on dimensions, meaning the number of values in each embedding. Document the model and configuration. Changing models later can require rebuilding embeddings, even when the dimensions match.
Supabase row-level security controls which rows a caller can access. Search filters help organize results; they do not replace authorization.
The database stores note text and metadata; uploaded files may need separate storage and backups. See the recovery inventory in Part 6 before relying on a backup.
From the plan to a test project
Part 1 stopped at a plan. Before running this build, create or select an isolated Supabase test project and approve the embedding provider and test budget. Obtain credentials through those services and enter them in the protected configuration your agent identifies, never in a chat message. Ask the agent to check the required runtime and tools before proposing installations.
For this first test, have the agent provide a command or tool invocation you can run from the project workspace. It should call the save/search code and connect to the test database. Record the working directory, configuration location, and how to repeat the call. A successful database connection alone is not the finished result.
In my implementation
The implementation reviewed for this series in October 2026 prefers search_memories_v3, combining semantic, full-text, literal, and typo-tolerant matches. It can fall back to older function-call forms when needed. Those are details of an existing implementation, not requirements for your first build. Start with keyword plus semantic search before adding more stages.
Prompt: build the smallest working pipeline
Implement the database foundation for the Open Brain plan we approved.
Inspect the repository and current Supabase documentation. Propose the
schema, embedding model/configuration, cost estimate, and access model
before changing a remote database. Use a separate test environment.
Preserve existing IDs, metadata and search contracts; prepare additive
migrations instead of replacing a working schema.
Preserve original text, source, capture time, stable IDs, and useful
labels. Validate extracted metadata. Keep provider credentials on the
server and provide placeholders in example configuration files.
Implement save, get-by-ID, and hybrid search combining keyword and
semantic results. Use the same embedding configuration for notes and
queries. Apply authorization and requested filters throughout search.
Provide repeatable save, get-by-ID, and search commands or tool calls.
State where to run them and how they load protected configuration without
printing secrets. Show the returned source text and IDs, not just a
success message. Do not require a bot or browser interface for this test.
Record reproducible database changes. Test with synthetic notes only,
within the API budget I approve. Report actual checks and failures;
do not call a row insertion alone an end-to-end search test.Check the result
Save these three fictional notes. Give the first two the project label Survey analysis and the third the label Travel planning. The labels let you ask for notes from one project without mixing in another:
Survey analysis: “Ana will send the code on Friday.”Survey analysis: “The analysis script is named analysis.do.”Travel planning: “Luis will send the train tickets on Monday.”
First search for “Who will share the script, and when?” The note about Ana should appear even though it says “code” rather than “script.” Next, search for analysis.do; that should find the note with the exact filename. Then repeat the first search with the Survey analysis project filter. The travel note should not appear. Check the returned IDs against the saved records.
Here is an illustrative interaction, not a transcript from my deployment or a required response format:
Save: Ana will send the code on Friday. [project: Survey analysis]
Returned ID: <note-id>
Search: Who will share the script, and when? [project filter: Survey analysis]
Expected match:
ID: <the same note-id>
Original text: Ana will send the code on Friday.
Replace the placeholder with the ID your save call returns. Use the get-by-ID call to confirm that the search result points to that record, rather than to a generated answer with no source.
Also test a caller without permission. A successful owner search says nothing about whether someone else can read the same notes.
Optional: connect an AI client
MCP is a protocol that lets compatible AI clients call tools. It can expose the same save and search functions without creating another database.
Add an MCP interface to the existing save/get/search functions if my
chosen client supports it. Follow that client's current documentation.
Explain each tool's permissions. Keep credentials out of generated
chat output. Verify a synthetic save and retrieval from the client,
and distinguish client configuration from a successful connection.Supabase’s hybrid-search guide explains the database approach. Your agent should adapt it to your access model and languages.
If a check fails
If the exact filename is missing, inspect keyword matching and the saved text. If a paraphrase fails, check that saving and searching use the same embedding configuration. If an unauthorized caller sees a note, stop and fix access controls before adding data.
Keep the three test notes and their IDs. They will become a small regression test you can rerun after each change.
Next: evaluate retrieval, or add optional Telegram capture if phone capture is your next need.
Previous: the introduction and computer setup. Complete the access and recovery checks before adding real notes.