#2408·cocoindex

[BUG] `@coco.fn(batching=True)` / `@coco.fn(runner=...)` 都拒绝异步和同步函数;文档中记录的异步形式无法使用

作者: hardness1020创建于 2026年9月13日更新于 2026年9月13日

Describe the bug

  • With batching=True, runner=..., or max_batch_size=..., @coco.fn picks _SyncFunctionBuilder.
  • That builder rejects async def ("use @coco.fn.as_async"). For sync def, _build_sync rejects batching / runner ("must be async"). No input passes.
  • Docs, docstring, and types all say the async form works:
    • docs/src/content/docs/programming_guide/function.mdx:293: "If the underlying function is already async def, @coco.fn(batching=True) works directly."
    • function.mdx:325: example @coco.fn(batching=True, max_batch_size=64) on async def embed(...). Raises at import when copied verbatim.
    • function.mdx:357: same claim for runner: "If the underlying function is already async def, @coco.fn(runner=...) works directly."
    • _AsyncBatchedDecorator (function.py:114-138) and the overload at :1969-1981. mypy types the docs example as AsyncFunction[[str], list[float]], then runtime raises.
  • Side effect: @coco.fn(max_batch_size=32) on sync def builds a plain SyncFunction and silently drops the option; on async def it raises the misleading "Async functions are not supported" message.
  • All in-repo callers use @coco.fn.as_async(...) (ops/sentence_transformers.py, ops/litellm.py, tests/core/test_function_batching.py), so CI never hits it. Users following the docs do.

内容来源: cocoindex-io/cocoindex