Skip to content
HALOWERK

Denkwerk

context pack

Selects passages greedily by Maximal Marginal Relevance (Carbonell and Goldstein 1998): lambda * relevance - (1 - lambda) * maximum TF-IDF cosine similarity to the passages already chosen; passages that no longer fit the budget are skipped. Relevance is the supplied score divided by the highest score, or the BM25 score against the query divided by the highest one. Each passage is rendered with a template such as "[{id}] {text}" and the final context is counted exactly with the chosen OpenAI.

POST https://denk.halowerk.com/v1/context-pack

Inputs

Fields of the published input schema
FieldTypeRequiredDescription
querystringNo
passagesarrayYesStrings or objects {id, text}.
budget_tokensintegerYes
lambdanumberNo
orderstringNo
templatestringNo
separatorstringNo
encodingstringNoOpenAI encoding used for token counts.
Show full input schema
{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "passages",
    "budget_tokens"
  ],
  "properties": {
    "query": {
      "type": "string",
      "maxLength": 2000
    },
    "passages": {
      "type": "array",
      "minItems": 1,
      "maxItems": 300,
      "description": "Strings or objects {id, text}.",
      "items": {
        "anyOf": [
          {
            "type": "string",
            "minLength": 1,
            "maxLength": 20000
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "maxLength": 128
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 20000
              },
              "score": {
                "type": "number"
              }
            }
          }
        ]
      }
    },
    "budget_tokens": {
      "type": "integer",
      "minimum": 1,
      "maximum": 2000000
    },
    "lambda": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "default": 0.7
    },
    "order": {
      "type": "string",
      "enum": [
        "selection",
        "source",
        "edges"
      ],
      "default": "selection"
    },
    "template": {
      "type": "string",
      "maxLength": 200,
      "default": "[{id}] {text}"
    },
    "separator": {
      "type": "string",
      "maxLength": 20,
      "default": "\n\n"
    },
    "encoding": {
      "type": "string",
      "enum": [
        "cl100k_base",
        "o200k_base"
      ],
      "default": "cl100k_base",
      "description": "OpenAI encoding used for token counts."
    }
  }
}

Open original schema

Published input example

{
  "query": "Kündigungsfrist Mietvertrag",
  "budget_tokens": 200,
  "passages": [
    {
      "id": "a",
      "text": "Die Kündigungsfrist beträgt drei Monate.",
      "score": 0.9
    },
    {
      "id": "b",
      "text": "Die Kaution beträgt drei Monatsmieten.",
      "score": 0.4
    }
  ]
}

Result & documentation

Machine-readable documentation of this hub

Source of this page: the published HALOWERK catalog. Updated: 2026-11-17 UTC.

More endpoints in this hub

All endpoints in this hub →