Search Code Chunks
Search for raw code chunks without parent document expansion. Returns precise code snippets.
Endpoint
POST /queries/search/:repoId/chunk
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
repoId | string | ✅ Yes | Repository identifier to search within |
Request Body
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
prompt | string | ✅ Yes | - | Natural language search query |
k | number | No | 5 | Number of results (max: 100) |
meta | object | No | - | Additional metadata filters |
Example Request
curl -X POST http://localhost:3000/queries/search/auth-service/chunk \
-H "Content-Type: application/json" \
-d '{
"prompt": "JWT token validation",
"k": 5
}'
Response
{
"results": [
{
"id": "chunk-abc123",
"content": "@Injectable()\nexport class AuthService {\n validateUser(token: string) {\n // validation logic\n }\n}",
"repoId": "my-repo",
"metadata": {
"team": "backend",
"filePath": "src/auth/auth.service.ts"
}
}
]
}
Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Chunk identifier |
content | string | Raw chunk content (code snippet, not full file) |
repoId | string | Repository identifier |
metadata | object | Custom metadata including filePath |
Key Difference from /queries/search/:repoId
| Feature | /queries/search/:repoId | /queries/search/:repoId/chunk |
|---|---|---|
| Returns | Full file content | Raw code snippets |
k multiplier | k * 3 internally | Exactly k chunks |
| Parent lookup | Yes (fetches full files) | No (direct chunks) |
| Response time | Slower | Faster |
| Use case | Understanding context | Precise snippets |
When to Use Each Endpoint
| Use Case | Recommended Endpoint |
|---|---|
| Need full file context | POST /queries/search/:repoId |
| Need precise code snippets | POST /queries/search/:repoId/chunk |
| Building code completion | POST /queries/search/:repoId/chunk |
| Understanding file structure | POST /queries/search/:repoId |
| RAG for chat assistants | POST /queries/search/:repoId/chunk |
Example: Search with Metadata Filters
curl -X POST http://localhost:3000/queries/search/backend-api/chunk \
-H "Content-Type: application/json" \
-d '{
"prompt": "Database connection pooling",
"k": 10,
"meta": {
"team": "platform"
}
}'
Status Codes
| Code | Description |
|---|---|
200 | Search completed |
400 | Invalid query parameters |
404 | Repository not found |
500 | Search failed |