-
Notifications
You must be signed in to change notification settings - Fork 0
search api guide
The Semantic Code Search API provides powerful search capabilities with advanced filtering options, including semantic type information. This guide covers all available search parameters and response formats with practical examples.
- Search Endpoint
- Request Parameters
- Response Format
- Basic Search Examples
- Advanced Type Filtering
- Combining Filters
- Response Examples
- Best Practices
POST /search
Performs semantic search across indexed code chunks with support for various filtering options.
| Parameter | Type | Required | Description | Default |
|---|---|---|---|---|
query |
string | ✅ | Search query text | - |
limit |
int | ❌ | Maximum results to return (1-100) | 10 |
offset |
int | ❌ | Pagination offset | 0 |
repository_ids |
[]uuid | ❌ | Filter by specific repositories | [] |
languages |
[]string | ❌ | Filter by programming languages | [] |
file_types |
[]string | ❌ | Filter by file extensions | [] |
similarity_threshold |
float64 | ❌ | Minimum similarity score (0.0-1.0) | 0.7 |
sort |
string | ❌ | Sort order (see below) | "similarity:desc" |
| Enhanced Type Filtering | ||||
types |
[]string | ❌ | Filter by semantic construct types | [] |
entity_name |
string | ❌ | Filter by entity name (partial match) | "" |
visibility |
[]string | ❌ | Filter by visibility modifiers | [] |
-
similarity:desc- Most similar first (default) -
similarity:asc- Least similar first -
file_path:asc- Alphabetical by file path -
file_path:desc- Reverse alphabetical by file path
Available values for types parameter:
| Type | Description | Example |
|---|---|---|
function |
Standalone functions | func calculateTax() |
method |
Class/struct methods | func (u *User) Login() |
class |
Class definitions | class UserManager |
struct |
Struct definitions | type User struct |
interface |
Interface definitions | type Repository interface |
enum |
Enumerations | enum Status { Active, Inactive } |
variable |
Variable declarations | var apiKey string |
constant |
Constants | const MaxRetries = 3 |
field |
Struct/class fields | Name string |
property |
Properties | public string Name { get; set; } |
module |
Modules/packages | package auth |
namespace |
Namespaces | namespace MyApp.Auth |
type |
Type definitions | type UserID int |
fragment |
Generic code fragments | Mixed content |
Available values for visibility parameter:
-
public- Publicly accessible -
private- Private scope -
protected- Protected scope -
internal- Internal/package scope
{
"results": [SearchResultDTO],
"search_metadata": {
"total_results": 42,
"execution_time_ms": 123,
"query": "implement authentication middleware",
"applied_filters": {
"languages": ["go", "typescript"],
"types": ["function", "method"],
"file_types": [".go", ".ts"],
"similarity_threshold": 0.7,
"iterative_scan_used": true
}
}
}{
"chunk_id": "550e8400-e29b-41d4-a716-446655440000",
"content": "func AuthMiddleware(next http.Handler) http.Handler {\n return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n // Authentication logic here\n next.ServeHTTP(w, r)\n })\n}",
"similarity_score": 0.95,
"repository": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "web-api",
"url": "https://github.com/company/web-api"
},
"file_path": "middleware/auth.go",
"language": "go",
"start_line": 15,
"end_line": 22,
"type": "function",
"entity_name": "AuthMiddleware",
"parent_entity": "",
"qualified_name": "middleware.AuthMiddleware",
"signature": "AuthMiddleware(next http.Handler) http.Handler",
"visibility": "public"
}curl -X POST http://localhost:8080/search \
-H "Content-Type: application/json" \
-d '{
"query": "user authentication",
"limit": 5
}'{
"query": "database connection",
"languages": ["go", "python"],
"limit": 10
}{
"query": "error handling",
"repository_ids": ["123e4567-e89b-12d3-a456-426614174000"],
"similarity_threshold": 0.8
}{
"query": "calculate total price",
"types": ["function"],
"limit": 15
}{
"query": "user validation",
"types": ["method"],
"entity_name": "validate"
}{
"query": "repository pattern",
"types": ["interface"],
"visibility": ["public"]
}{
"query": "authentication logic",
"entity_name": "login",
"types": ["function", "method"]
}{
"query": "implement user service",
"languages": ["go"],
"types": ["struct", "method"],
"visibility": ["public"],
"entity_name": "user",
"similarity_threshold": 0.75,
"limit": 20,
"sort": "similarity:desc"
}{
"query": "payment processing workflow",
"repository_ids": [
"123e4567-e89b-12d3-a456-426614174000",
"987fcdeb-51a2-43d1-9876-543210987654"
],
"types": ["function", "method", "class"],
"languages": ["go", "typescript", "java"],
"file_types": [".go", ".ts", ".java"],
"visibility": ["public"],
"limit": 50,
"offset": 0
}{
"results": [
{
"chunk_id": "550e8400-e29b-41d4-a716-446655440000",
"content": "func ProcessPayment(amount float64, method PaymentMethod) (*PaymentResult, error) {\n // Validate payment amount\n if amount <= 0 {\n return nil, errors.New(\"invalid amount\")\n }\n \n // Process payment based on method\n switch method {\n case CreditCard:\n return processCreditCard(amount)\n case PayPal:\n return processPayPal(amount)\n default:\n return nil, errors.New(\"unsupported payment method\")\n }\n}",
"similarity_score": 0.92,
"repository": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "payment-service",
"url": "https://github.com/company/payment-service"
},
"file_path": "internal/payment/processor.go",
"language": "go",
"start_line": 45,
"end_line": 60,
"type": "function",
"entity_name": "ProcessPayment",
"parent_entity": "",
"qualified_name": "payment.ProcessPayment",
"signature": "ProcessPayment(amount float64, method PaymentMethod) (*PaymentResult, error)",
"visibility": "public"
},
{
"chunk_id": "661f9500-f39c-52e5-b827-557766551111",
"content": "type PaymentProcessor struct {\n gateway PaymentGateway\n logger *log.Logger\n config *ProcessorConfig\n}\n\n// NewPaymentProcessor creates a new payment processor instance\nfunc NewPaymentProcessor(gateway PaymentGateway, logger *log.Logger, config *ProcessorConfig) *PaymentProcessor {\n return &PaymentProcessor{\n gateway: gateway,\n logger: logger,\n config: config,\n }\n}",
"similarity_score": 0.88,
"repository": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "payment-service",
"url": "https://github.com/company/payment-service"
},
"file_path": "internal/payment/processor.go",
"language": "go",
"start_line": 15,
"end_line": 28,
"type": "struct",
"entity_name": "PaymentProcessor",
"parent_entity": "",
"qualified_name": "payment.PaymentProcessor",
"signature": "",
"visibility": "public"
}
],
"search_metadata": {
"total_results": 2,
"execution_time_ms": 156,
"query": "payment processing workflow",
"applied_filters": {
"languages": ["go"],
"types": ["function", "struct"],
"similarity_threshold": 0.7
}
}
}{
"results": [],
"search_metadata": {
"total_results": 0,
"execution_time_ms": 45,
"query": "nonexistent functionality",
"applied_filters": {
"similarity_threshold": 0.7
}
}
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "limit must be between 1 and 100",
"details": {
"field": "limit",
"provided_value": 150
}
}
}-
Use Natural Language: Write queries as you would describe the functionality
{"query": "validate user email address"} -
Combine Semantic Types: Use multiple types for broader search
{"types": ["function", "method"], "query": "authentication"} -
Entity Name Filtering: Use partial matching for flexible entity discovery
{"entity_name": "auth", "query": "login functionality"}
-
Set Appropriate Limits: Use reasonable limits to avoid overwhelming responses
{"limit": 20, "offset": 0} -
Use Similarity Threshold: Filter out low-quality matches
{"similarity_threshold": 0.8} -
Repository Filtering: Search specific repositories when possible - CRITICAL for pgvector iterative scanning
{"repository_ids": ["known-repo-id"]} -
Language and File Extension Filtering: These work seamlessly with pgvector iterative scanning to guarantee result counts
{"languages": ["go"], "file_types": [".go"]}
Problem Solved: Traditional vector search with filters often returns fewer results than requested because filters are applied after the index scan. For example, asking for 20 results might only return 3 if the filters are very selective.
Solution: pgvector 0.8.0+ iterative scanning automatically continues searching when filters reduce result count, ensuring you get the requested number of results.
{
"query": "database connection",
"repository_ids": ["backend-service"],
"languages": ["go"],
"limit": 15
}With iterative scanning enabled:
- pgvector performs initial vector search for 15 candidates
- Applies repository/language filters at SQL level
- If < 15 results remain, pgvector automatically expands search
- Continues until 15 matching results found or no more candidates
- Returns exactly the number of results you requested (if available)
✅ SQL-Level Filters (Full iterative scanning benefits):
-
repository_ids- Repository filtering -
languages- Programming language filtering -
file_types- File extension filtering -
types- Semantic construct filtering
-
entity_name- Entity name matching -
visibility- Visibility modifier filtering
Example with SQL-Level Filters:
{
"query": "authentication middleware",
"repository_ids": ["auth-service"],
"languages": ["go", "typescript"],
"types": ["function", "method"],
"file_types": [".go", ".ts"],
"limit": 20
}This query will return up to 20 highly relevant results, with pgvector automatically expanding the search scope if needed to find enough matches across your filtered repositories and languages.
-
Architecture Discovery: Find patterns across codebases
{ "query": "repository pattern implementation", "types": ["interface", "struct", "method"], "visibility": ["public"] } -
Code Quality Analysis: Find specific implementation patterns
{ "query": "error handling best practices", "types": ["function"], "languages": ["go"] } -
API Endpoint Discovery: Locate service endpoints
{ "query": "HTTP handler", "entity_name": "handler", "types": ["function", "method"], "file_types": [".go"] }
curl -X POST http://localhost:8080/search \
-H "Content-Type: application/json" \
-d '{
"query": "user authentication and authorization",
"types": ["function", "method"],
"entity_name": "auth",
"visibility": ["public"],
"languages": ["go"],
"limit": 10
}'curl -X POST http://localhost:8080/search \
-H "Content-Type: application/json" \
-d '{
"query": "database repository pattern",
"types": ["struct", "interface", "method"],
"entity_name": "repository",
"visibility": ["public"],
"limit": 25,
"similarity_threshold": 0.75
}'curl -X POST http://localhost:8080/search \
-H "Content-Type: application/json" \
-d '{
"query": "error handling and validation",
"types": ["function"],
"languages": ["go"],
"signature": "error",
"limit": 15
}'- No Results: Check similarity threshold and filters are not too restrictive
- Slow Queries: Use repository filtering and appropriate limits
- Validation Errors: Ensure all parameters are within acceptable ranges
- Maximum 100 requests per minute per API key
- Maximum 100 results per search request
- Queries longer than 1000 characters will be truncated
For more information, see:
Configuration
- [📖 Configuration Reference](configuration reference) - Complete reference guide
- Configuration
- API Configuration
- Database Configuration
- Gemini Configuration
- Git Configuration
- Logging Configuration
- Middleware Configuration
- NATS Configuration
- Worker Configuration