Search

Query your indexed data with semantic, keyword, or hybrid search.

The Search API lets you query indexed data across your collections using semantic search, keyword matching, or a combination of both.

Endpoints

POST /api/v1/search

Full-featured search with all parameters.

Request:

curl -X POST https://api.ballast.sh/v1/search 
  -H "Authorization: Bearer bk_your_api_key" 
  -H "Content-Type: application/json" 
  -d '{
    "collectionId": "col_abc123",
    "query": "remote work policy",
    "limit": 10,
    "rerank": true,
    "generateAnswer": true
  }'

Parameters:

FieldTypeRequiredDescription
collectionIdstringYesCollection UUID to search
querystringYesSearch query
limitintNoMax results (default: 10)
filtersarrayNoMetadata filters
rerankboolNoApply LLM reranking
expandQueryboolNoGenerate query variations
generateAnswerboolNoSynthesize answer from results

Response:

{
  "success": true,
  "results": [
    {
      "id": "doc_123",
      "score": 0.92,
      "content": "Our remote work policy allows...",
      "metadata": {
        "source": "notion",
        "title": "Company Policies",
        "url": "https://..."
      }
    }
  ],
  "query": "remote work policy",
  "answer": "The company's remote work policy allows employees to work from home up to 3 days per week...",
  "took": 245
}

GET /api/v1/collections/:id/search

Simpler search endpoint with query parameters.

Request:

curl "https://api.ballast.sh/v1/collections/col_abc123/search?query=remote%20work&limit=10" 
  -H "Authorization: Bearer bk_your_api_key"

Parameters:

FieldTypeRequiredDescription
idstringYesCollection ID (path parameter)
querystringYesSearch query
responseTypestringNoraw (default) or completion
limitintNoMax results (default: 10)

Response Types:

  • raw: Returns search results only
  • completion: Returns results plus an AI-generated answer

Search Results

Each result includes:

FieldDescription
idUnique document/chunk identifier
scoreRelevance score (0-1)
contentMatched content snippet
metadataSource-specific metadata

Common Metadata Fields

FieldDescription
sourceSource type (slack, notion, gdrive, etc.)
titleDocument or message title
urlLink to original content
authorContent author
created_atCreation timestamp
updated_atLast update timestamp

Filters

Apply metadata filters to narrow results:

{
  "collectionId": "col_abc123",
  "query": "budget",
  "filters": [
    {
      "field": "source",
      "operator": "eq",
      "value": "gsheets"
    },
    {
      "field": "created_at",
      "operator": "gte",
      "value": "2024-01-01"
    }
  ]
}

Operators:

OperatorDescription
eqEquals
neqNot equals
gtGreater than
gteGreater than or equal
ltLess than
lteLess than or equal
inIn array
containsContains substring

Search Features

Query Expansion

When expandQuery: true, Ballast generates semantic variations of your query to improve recall:

{
  "query": "remote work policy",
  "expandQuery": true
}

For “remote work policy”, might also search for:

  • “work from home guidelines”
  • “distributed team rules”
  • “telecommuting policy”

Reranking

When rerank: true, results are reordered using an LLM for better relevance:

{
  "query": "budget approval process",
  "rerank": true
}

Reranking uses Cohere or Jina models to evaluate semantic relevance beyond vector similarity.

Answer Generation

When generateAnswer: true, an LLM synthesizes an answer from the top results:

{
  "query": "What is the vacation policy?",
  "generateAnswer": true
}

Response includes:

{
  "results": [...],
  "answer": "The vacation policy provides 20 days of PTO annually, plus..."
}

Error Responses

StatusErrorDescription
400invalid_requestMissing required fields
401unauthorizedInvalid or missing authentication
403forbiddenNo access to collection
404not_foundCollection doesn’t exist
500search_failedInternal search error

Best Practices

Keep queries focused

  • Short, specific queries often work better than long ones
  • Use filters to narrow scope instead of adding terms

Use filters for structured data

  • Filter by source, date, author for precise results
  • Combine multiple filters for complex queries

Enable reranking for quality

  • Reranking improves relevance but adds latency
  • Best for user-facing searches where quality matters

Use answer generation sparingly

  • Only enable when you need synthesized answers
  • Adds significant latency and token usage

Handle empty results gracefully

  • Check results.length before processing
  • Consider suggesting alternative queries