Skip to main content

Code Search

The code search tool provides semantic search over indexed code repositories. Agents can query a codebase in natural language and receive file names, line numbers, and relevant code snippets.

Tool: search_codebase

Searches indexed repositories using vector embeddings and returns the most relevant code snippets.

Arguments

ArgumentTypeDescription
querystringNatural language description of what to find
repo_idstringOptional — limit search to a specific repo
top_kintNumber of results to return (default 5)

1. Enable code embedding

In Settings, toggle Code Repository Indexing on. This requires PostgreSQL with the pgvector extension — see PostgreSQL + pgvector setup below.

2. Add a repository

Go to Settings → Code Repos and add a repository:

FieldDescription
NameDisplay name
PathAbsolute path to the repo on the host
DescriptionWhat this codebase does
Included patternsFile types to index (default: .py, .ts, .tsx, .js, .jsx, .rs, .go, .java, .md, .html, .vue, .css, .scss, .cpp, .c)
Excluded patternsFiles/dirs to skip (default: node_modules, __pycache__, venv, .git, *.pyc, dotfiles)
Embedding model providerProvider for generating embeddings (gemini by default)

3. Index the repository

Click Index in the repository settings. Synapse walks the directory tree, generates vector embeddings for each file (chunked by function/class/section), and stores them in PostgreSQL with pgvector.

Indexing progress is shown as a status indicator: pending → indexing → indexed.

4. Assign repos to agents

In the agent editor, set repos to the list of repo IDs the agent should search:

"repos": ["repo-abc123", "repo-def456"]

Example queries

Find the function that handles MCP server registration
Where is the vault_write tool implemented?
Show me all places where the anthropic client is initialised
Find tests for the orchestration engine

Re-indexing

After making significant code changes, re-index to keep the embeddings up to date. Click Re-index in the repository settings or wait for the automatic re-index (if configured).

PostgreSQL + pgvector setup

Toggle Code Repository Indexing in Settings. Synapse checks your PostgreSQL setup and guides you through any missing pieces:

StateWhat Synapse shows
PostgreSQL not installedInstall instructions for Ubuntu/Debian, macOS, and Windows
No database configuredA form to enter host, port, username, password, and database name — click Create Database and Synapse creates the database and enables pgvector
Existing connection brokenThe same credentials form pre-filled, with the failing URL shown — click Save & Connect to reconfigure
pgvector extension missingInstructions to run CREATE EXTENSION vector; (and OS package install commands if needed)

Or set it up manually:

CREATE DATABASE synapse;
\c synapse
CREATE EXTENSION vector;