Document Scoring Methods

When aggregating chunk-level search results into document-level scores, LocalVectorDB supports three scoring methods. Each has a different strength depending on your use case.

Note

Earlier releases exposed eight additional heuristic methods (worst, weighted_average, harmonic_mean, diminishing_returns, statistical, robust_mean, percentile, geometric_mean). They were removed in v0.1.0: measured on the NFCorpus retrieval benchmark none of them beat the three methods below, they overlapped heavily, and several were non-monotonic (adding a low-scoring chunk could reorder documents). Passing a removed name now raises ValueError.

Methods

"best"

Uses the highest-scoring chunk as the document score. Choose this when you want documents ranked by their single most relevant passage, regardless of overall document quality.

Parameters: None

"average"

Takes the arithmetic mean of all chunk scores. Good for documents where overall content quality matters more than peak relevance.

Parameters: None

"frequency_boost" (Default)

Boosts the best chunk score based on the number of quality chunks found, rewarding documents with multiple relevant passages. Ideal for comprehensive documents where breadth of coverage indicates relevance.

Parameters:

  • frequency_bias (0.0-1.0, default=0.3): Controls how much to boost scores based on chunk frequency. Higher values favor documents with more matching chunks.

Choosing a Method

  • Single best passage matters most: Use "best"

  • Overall document quality important: Use "average"

  • Want to reward multiple relevant sections: Use "frequency_boost" (default)

How Raw Scores Are Computed

Before document-level aggregation is applied, each chunk receives a raw similarity score between 0.0 and 1.0. The normalization depends on the search type.

Using Scoring Methods via the Server API

All search endpoints accept document_scoring_method and document_scoring_options in the request body. These parameters are forwarded directly to the local database’s query() method.

# Unified query endpoint
curl -X POST http://localhost:8000/api/v1/databases/my_db/query \
  -H "Content-Type: application/json" \
  -d '{
    "query": "machine learning",
    "search_type": "hybrid",
    "return_type": "documents",
    "k": 10,
    "score_threshold": 0.3,
    "vector_weight": 0.5,
    "document_scoring_method": "frequency_boost",
    "document_scoring_options": {
      "frequency_bias": 0.3
    }
  }'

The convenience endpoints (/search/vector, /search/keyword, /search/hybrid) also accept these parameters with the same schema.

Note

document_scoring_method and document_scoring_options only take effect when return_type is "documents". For chunk-level return types ("chunks", "context", "enriched"), raw chunk scores are returned directly.