DuckDB functions that answer questions about text
Ask a question in WHERE, SELECT, or ORDER BY.
Install
| Channel | Note |
|---|---|
duckdb -unsigned | The -unsigned flag lets DuckDB load a local extension file. The query loads that file first. |
Set THINKTHEN_API_KEY in the environment.
A first call
LOAD './thinkthen.duckdb_extension';
CREATE TABLE tickets AS SELECT * FROM (VALUES
(1, 'My parcel is a week late. Not okay.'),
(2, 'Thanks for the quick help yesterday!'),
(3, 'We are locked out of our account.'),
(4, 'I was billed twice for one order.')
) t(id, body);
WITH judged AS (
SELECT
id,
body,
thinkthen_decide('Is this a complaint?', body)
AS is_complaint
FROM tickets
)
SELECT id, thinkthen_choose('Which team owns this?',
body, ['billing', 'shipping', 'account']) AS team
FROM judged
WHERE is_complaint;What DuckDB printed
id|team 1|shipping 3|account 4|billing
Not sure comes back as NULL. Branch on it and send those cases to a person. Each function page shows its DuckDB call.
Run facts
thinkthen_usage() gives the totals for the process.
Errors
A failure is an error whose text starts thinkthen <kind>: . It never reads as NULL.
Settings and recording
SET thinkthen_record writes a recording to a folder. SET thinkthen_replay answers from that recording with no connection. The Settings page lists every setting.
What is different in DuckDB
- DuckDB hands the extension up to 2,048 rows at a time. One call judges those rows together, and
SET thinkthen_max_requestscaps that call.
On GitHub: github.com/botassembly/thinkthen