Beginner~12 minAI Workflows

Semantic Search & Code Intelligence

Find anything in your project by meaning — docs, tasks, memory, and code symbols. Search smarter with local ONNX embeddings and AST-based code graph.

SearchCode IntelligenceONNXCode Graph
knowns init
Enable search
Code ingest
Search by meaning
Trace dependencies

What you'll learn

How to use semantic search and code intelligence to find anything in your project — by meaning, not just keywords. Search docs, tasks, memory, and even code symbols from one interface.

The Problem

You know the pattern exists somewhere. You wrote it last month. But you can't remember the exact name, the file, or the keywords. Traditional search fails because you're searching for meaning, not text.

Knowns solves this with:

  • Semantic search — find docs, tasks, and memory by meaning using local ONNX embeddings
  • Code intelligence — search symbols, trace dependencies, and explore your code graph

No external API calls. Everything runs locally.


Enable Semantic Search

If you haven't already, enable semantic search during init:

knowns init
# → "Enable semantic search?" → y
# → "Select model:" → gte-small (recommended, ~50MB)

Or enable on an existing project:

knowns config set search.semantic.enabled true
knowns model download gte-small
knowns search --reindex

Model runs locally

The ONNX model runs inside the Go binary — no Python, no Node.js, no API keys. First search is slower while the model loads into memory; subsequent searches are fast.

Search by Meaning

This is where it gets interesting. You don't need exact keywords:

Semantic search
$ knowns search "how do we handle authentication errors"

DOC: patterns/auth (94%)
Section: ## Error Handling
Matched by: semantic

#42 [done] (89%)
Implement JWT error middleware
Matched by: semantic, keyword

MEMORY: "Auth errors return 401 with error code" (85%)
Matched by: semantic

Notice: the query says "authentication errors" but it finds "JWT error middleware" and "Auth errors" — because it understands meaning, not just words.

Search modes

# Hybrid (semantic + keyword) — default, best for most cases
knowns search "handle auth errors"

# Keyword only — when you know the exact term
knowns search "bcrypt" --keyword

# Filter by type
knowns search "api design" --type doc
knowns search "login bug" --type task
knowns search "token rotation" --type memory

Index Your Code

Semantic search covers docs, tasks, and memory. For code-level intelligence, you need to build the code index first:

# Build the code index (AST-based) — required before any code search
knowns code ingest

Run this first

knowns code ingest must run at least once before you can use knowns code search, knowns code symbols, or knowns code deps. It scans your source files and builds an AST-based index of all symbols and relationships.

After the initial ingest, keep it fresh while you work:

knowns code watch

This indexes functions, classes, methods, interfaces, and their relationships across Go, TypeScript, JavaScript, and Python files.

Search Code Symbols

Find code by what it does, not where it lives:

Code search
$ knowns code search "oauth login handler"

src/routes/auth.ts
→ loginHandler (function, line 42)
→ Calls: validateCredentials, generateToken
→ Imported by: src/app.ts

src/middleware/oauth.ts
→ oauthCallback (function, line 15)
→ Calls: exchangeCode, createSession

Inspect symbols in a scope

# All symbols in a directory
knowns code symbols --path src/auth/

# Filter by kind
knowns code symbols --kind function
knowns code symbols --kind class
Symbol listing
$ knowns code symbols --path src/auth/

src/auth/login.ts
├── loginHandler (function)
├── validateEmail (function)
└── LoginRequest (interface)

src/auth/middleware.ts
├── authGuard (function)
└── extractToken (function)

Trace Dependencies

Understand how code connects:

# What does this file import?
knowns code deps --type imports

# What calls what?
knowns code deps --type calls

# Full dependency graph
knowns code deps
Dependency trace
$ knowns code deps --type imports

src/routes/auth.ts
→ imports: src/services/auth-service.ts
→ imports: src/middleware/validate.ts
→ imports: src/utils/jwt.ts

src/services/auth-service.ts
→ imports: src/repositories/user-repo.ts
→ imports: src/utils/bcrypt.ts

This is powerful for understanding unfamiliar codebases — trace from an endpoint down to the database layer in seconds.

Use with AI via MCP

When MCP is connected, your AI assistant uses these tools automatically:

AI using search + code intelligence
You: How does our auth middleware work?

AI:  [Calls search({ action: "search", query: "auth middleware" })]
   [Calls code({ action: "search", query: "auth middleware" })]
   [Calls code({ action: "deps", type: "imports" })]

   Your auth middleware is in src/middleware/auth.ts:
   - Extracts JWT from Authorization header
   - Validates token using src/utils/jwt.ts
   - Attaches user to request context
   - Returns 401 if token is invalid or expired

   It's imported by 12 route files and depends on
   the jwt utility and user repository.

The AI combines semantic search (docs, memory) with code intelligence (symbols, deps) to give you a complete answer.


Retrieval Order

When you need context — whether manually or via AI — follow this order:

StepToolPurpose
1knowns searchFind relevant docs, tasks, memory
2knowns code searchDiscover code entry points
3knowns code symbolsVerify what's indexed in a scope
4knowns code depsTrace relationships between files

Search vs Code Intelligence

Semantic SearchCode Intelligence
Searches docs, tasks, memorySearches code symbols and files
Finds by meaning (vector similarity)Finds by AST structure
Great for 'how do we handle X?'Great for 'where is function X defined?'
Returns text chunks with scoresReturns symbols with relationships
Always availableRequires knowns code ingest

Tips

Reindex after big changes

After major refactors or bulk doc updates, rebuild the index:

knowns search --reindex    # docs, tasks, memory
knowns code ingest         # code symbols

Use type filters

When you know what you're looking for, filter by type to reduce noise:

knowns search "auth" --type memory   # only memory entries
knowns search "api" --type doc       # only docs

Check search health

If results seem off, check the index status:

knowns search --status-check
knowns model status

What's next?

Try Bug Triage with Memory to see search in action during debugging, or read the Semantic Search docs and Code Intelligence docs for the full reference.