Search Shortcut cmd + k | ctrl + k

Compose fast bounded judgments, semantic resolution, and selective LLM reasoning with provenance

Maintainer(s): prasanthj

Installing and Loading

INSTALL dc FROM community;
LOAD dc;

Example

INSTALL dc FROM community;
LOAD dc;

CREATE SECRET cognition (
  TYPE dc,
  SYSTEM_ONE_PROVIDER 'typesafe',
  SYSTEM_ONE_API_KEY 'ts-...',
  SYSTEM_ONE_MODEL 'jev-1.13.0',
  SYSTEM_TWO_PROVIDER 'openai',
  SYSTEM_TWO_API_KEY 'sk-...',
  SYSTEM_TWO_MODEL 'gpt-5.6-luna'
);

SELECT item,
       result.choice AS category,
       result.confidence
FROM (
  SELECT item,
         system_one_choice(
           item,
           'Classify the support request.',
           '{"billing":"payments", "technical":"product failures", "security":"access and data risk"}'::JSON
         ) AS result
  FROM support_requests
);

About dc

dc brings a two-stage AI enrichment pipeline into DuckDB SQL.

System One handles bounded, highly batchable judgments with system_one_choice, system_one_score, system_one_noul, and the relation-oriented system_one_stream. Semantic Resolution assigns foreign keys from per-row candidates with system_one_resolve and system_one_resolve_stream, including explicit matched, ambiguous, and no_match outcomes. System Two handles generation, summarization, and structured extraction with system_two_generate, system_two_summarize, and system_two_extract.

The two paths compose through ordinary SQL. A query can classify every row with System One, escalate only results below a confidence threshold to System Two, and retain a single final column alongside the candidate, confidence, threshold, escalation result, and selected source.

The native extension deduplicates equivalent work, batches rows, bounds concurrent provider requests, validates responses, stops queued work and aborts active client transfers when DuckDB interrupts a query, and offers query-local coalescing plus optional per-connection TTL/LRU caches. dc_stats() reports request, item, cache, retry, error, token, byte, and latency metrics independently for both systems.

Provider credentials are stored through DuckDB's Secret Manager and are redacted from duckdb_secrets(). Plain HTTP endpoints are rejected except for loopback testing, and SET enable_external_access = false disables provider calls.

Full SQL reference and runnable examples: https://github.com/prasanthj/duckdb-dual-cognition

Added Functions

function_name function_type description comment examples
dc_cache_clear scalar NULL NULL  
dc_stats table NULL NULL  
system_one_choice scalar NULL NULL  
system_one_noul scalar NULL NULL  
system_one_resolve scalar NULL NULL  
system_one_resolve_stream table NULL NULL  
system_one_score scalar NULL NULL  
system_one_stream table NULL NULL  
system_two_extract scalar NULL NULL  
system_two_generate scalar NULL NULL  
system_two_summarize scalar NULL NULL  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

name description input_type scope aliases
dc_system_one_batch_size Maximum questions per HTTP request BIGINT GLOBAL []
dc_system_one_cache_bytes Query cache serialized byte budget (0 disables) BIGINT GLOBAL []
dc_system_one_concurrency Concurrent requests (global ceiling 10) BIGINT GLOBAL []
dc_system_one_endpoint Trusted TypeSafe endpoint VARCHAR GLOBAL []
dc_system_one_max_questions_per_query Maximum billable questions dispatched by one query BIGINT GLOBAL []
dc_system_one_max_request_bytes Serialized request byte cap BIGINT GLOBAL []
dc_system_one_max_requests_per_query Maximum logical HTTP requests dispatched by one query BIGINT GLOBAL []
dc_system_one_max_retries Retries for transient transport, 429 and 5xx errors BIGINT GLOBAL []
dc_system_one_model TypeSafe model VARCHAR GLOBAL []
dc_system_one_retry_base_ms Initial exponential retry delay BIGINT GLOBAL []
dc_system_one_retry_max_delay_ms Maximum retry delay including Retry-After BIGINT GLOBAL []
dc_system_one_session_cache_bytes Opt-in connection LRU serialized byte budget BIGINT GLOBAL []
dc_system_one_session_cache_ttl_ms Connection cache non-sliding TTL BIGINT GLOBAL []
dc_system_one_timeout_ms HTTP timeout per attempt BIGINT GLOBAL []
dc_system_two_batch_size Maximum rows per Responses request BIGINT GLOBAL []
dc_system_two_cache_bytes System Two query-cache serialized byte budget BIGINT GLOBAL []
dc_system_two_concurrency Concurrent Responses requests BIGINT GLOBAL []
dc_system_two_endpoint OpenAI Responses endpoint VARCHAR GLOBAL []
dc_system_two_max_items_per_query Maximum uncached System Two rows per query BIGINT GLOBAL []
dc_system_two_max_request_bytes Serialized Responses request byte cap BIGINT GLOBAL []
dc_system_two_max_requests_per_query Maximum System Two HTTP requests per query BIGINT GLOBAL []
dc_system_two_max_retries Retries for transient transport, 429 and 5xx errors BIGINT GLOBAL []
dc_system_two_retry_base_ms Initial exponential retry delay BIGINT GLOBAL []
dc_system_two_retry_max_delay_ms Maximum retry delay including Retry-After BIGINT GLOBAL []
dc_system_two_session_cache_bytes System Two connection-cache serialized byte budget BIGINT GLOBAL []
dc_system_two_session_cache_ttl_ms System Two connection-cache TTL BIGINT GLOBAL []
dc_system_two_timeout_ms HTTP timeout per attempt BIGINT GLOBAL []