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:
$ 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:
$ 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
$ 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
$ 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:
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:
| Step | Tool | Purpose |
|---|---|---|
| 1 | knowns search | Find relevant docs, tasks, memory |
| 2 | knowns code search | Discover code entry points |
| 3 | knowns code symbols | Verify what's indexed in a scope |
| 4 | knowns code deps | Trace relationships between files |
Search vs Code Intelligence
| Semantic Search | Code Intelligence |
|---|---|
| Searches docs, tasks, memory | Searches 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 scores | Returns symbols with relationships |
| Always available | Requires 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.
Bạn sẽ học được gì
Cách dùng semantic search và code intelligence để tìm bất cứ thứ gì trong project — theo ý nghĩa, không chỉ keyword. Tìm docs, tasks, memory, và cả code symbols từ một giao diện duy nhất.
Vấn đề
Bạn biết pattern đó tồn tại ở đâu đó. Bạn viết nó tháng trước. Nhưng không nhớ tên chính xác, file nào, hay keyword gì. Search truyền thống fail vì bạn đang tìm theo ý nghĩa, không phải text.
Knowns giải quyết bằng:
- Semantic search — tìm docs, tasks, và memory theo ý nghĩa dùng ONNX embeddings chạy local
- Code intelligence — tìm symbols, trace dependencies, và explore code graph
Không gọi API bên ngoài. Mọi thứ chạy local.
Bật Semantic Search
Nếu chưa bật, enable semantic search khi init:
knowns init
# → "Enable semantic search?" → y
# → "Select model:" → gte-small (recommended, ~50MB)
Hoặc bật trên project đã có:
knowns config set search.semantic.enabled true
knowns model download gte-small
knowns search --reindex
Model chạy local
ONNX model chạy bên trong Go binary — không cần Python, Node.js, hay API key. Lần search đầu chậm hơn vì model đang load vào memory; các lần sau nhanh.
Tìm theo Ý nghĩa
Đây là phần hay nhất. Bạn không cần keyword chính xác:
$ knowns search "cách xử lý lỗi authentication" 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
Query nói "lỗi authentication" nhưng tìm được "JWT error middleware" và "Auth errors" — vì nó hiểu ý nghĩa, không chỉ từ ngữ.
Các chế độ search
# Hybrid (semantic + keyword) — mặc định, tốt nhất cho hầu hết trường hợp
knowns search "handle auth errors"
# Keyword only — khi bạn biết chính xác term
knowns search "bcrypt" --keyword
# Lọc theo loại
knowns search "api design" --type doc
knowns search "login bug" --type task
knowns search "token rotation" --type memory
Index Code
Semantic search cover docs, tasks, và memory. Để có code-level intelligence, bạn cần build code index trước:
# Build code index (AST-based) — bắt buộc chạy trước khi dùng code search
knowns code ingest
Chạy lệnh này trước
knowns code ingest phải chạy ít nhất một lần trước khi bạn dùng knowns code search, knowns code symbols, hay knowns code deps. Nó scan source files và build AST-based index cho tất cả symbols và relationships.
Sau lần ingest đầu tiên, giữ index fresh khi bạn làm việc:
knowns code watch
Nó index functions, classes, methods, interfaces, và relationships giữa chúng — hỗ trợ Go, TypeScript, JavaScript, và Python.
Tìm Code Symbols
Tìm code theo chức năng, không phải vị trí:
$ 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
Xem symbols trong một scope
# Tất cả symbols trong thư mục
knowns code symbols --path src/auth/
# Lọc theo loại
knowns code symbols --kind function
knowns code symbols --kind class
$ 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
Hiểu cách code kết nối với nhau:
# File này import gì?
knowns code deps --type imports
# Cái gì gọi cái gì?
knowns code deps --type calls
# Full dependency graph
knowns code deps
$ 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
Rất mạnh khi cần hiểu codebase lạ — trace từ endpoint xuống database layer trong vài giây.
Dùng với AI qua MCP
Khi MCP đã kết nối, AI assistant dùng các tool này tự động:
You: Auth middleware hoạt động thế nào?
AI: [Calls search({ action: "search", query: "auth middleware" })]
[Calls code({ action: "search", query: "auth middleware" })]
[Calls code({ action: "deps", type: "imports" })]
Auth middleware nằm ở src/middleware/auth.ts:
- Extract JWT từ Authorization header
- Validate token dùng src/utils/jwt.ts
- Attach user vào request context
- Return 401 nếu token invalid hoặc expired
Nó được import bởi 12 route files và depend vào
jwt utility và user repository.AI kết hợp semantic search (docs, memory) với code intelligence (symbols, deps) để cho bạn câu trả lời đầy đủ.
Thứ tự Retrieval
Khi cần context — dù thủ công hay qua AI — theo thứ tự này:
| Bước | Tool | Mục đích |
|---|---|---|
| 1 | knowns search | Tìm docs, tasks, memory liên quan |
| 2 | knowns code search | Khám phá code entry points |
| 3 | knowns code symbols | Xác nhận symbols đã index |
| 4 | knowns code deps | Trace relationships giữa files |
Search vs Code Intelligence
| Semantic Search | Code Intelligence |
|---|---|
| Tìm docs, tasks, memory | Tìm code symbols và files |
| Tìm theo ý nghĩa (vector similarity) | Tìm theo AST structure |
| Tốt cho 'chúng ta handle X thế nào?' | Tốt cho 'function X định nghĩa ở đâu?' |
| Trả về text chunks với scores | Trả về symbols với relationships |
| Luôn available | Cần chạy knowns code ingest |
Tips
Reindex sau thay đổi lớn
Sau refactor lớn hoặc cập nhật docs hàng loạt, rebuild index:
knowns search --reindex # docs, tasks, memory
knowns code ingest # code symbols
Dùng type filters
Khi biết mình tìm gì, lọc theo type để giảm noise:
knowns search "auth" --type memory # chỉ memory
knowns search "api" --type doc # chỉ docs
Kiểm tra search health
Nếu kết quả có vẻ sai, check index status:
knowns search --status-check
knowns model status
Tiếp theo
Thử Bug Triage with Memory để xem search trong thực tế khi debug, hoặc đọc Semantic Search docs và Code Intelligence docs để xem full reference.