Skip to content

NLP

Detect language, score sentiment, extract entities and tokenize text from queries

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/nlp/index.md to help me query NLP with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Extract named entities from a literal document, keyed back to its id.

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT id, ent_text, label
FROM nlp.main.entities((SELECT 1 AS id, 'Apple is based in California.' AS body), id := 'id', lang := 'en')
Result
id ent_text label
1 Apple ORG
1 California GPE

Quick start

Choose where to run NLP, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'nlp' AS nlp (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-nlp-worker'
);

3. Run a query

query.sql
SELECT id, ent_text, label
FROM nlp.main.entities((SELECT 1 AS id, 'Apple is based in California.' AS body), id := 'id', lang := 'en')
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'nlp' AS nlp (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-nlp-worker'
);

Overview

Classical NLP (spaCy + fastText + VADER): language ID, sentiment, NER, tokenization for SQL.

Catalog

Everything nlp exposes once attached — read straight from the worker's released build.

nlp 1 schema
main 1 table · 11 functions

Classical NLP: language ID, sentiment, NER, tokenization for SQL

Schema examples (10)
Examples (10)

Detect the language of a French string.

SELECT nlp.main.detect_lang('Bonjour tout le monde') AS lang;

Score the sentiment of a positive English review.

SELECT nlp.main.sentiment('I absolutely love this product!') AS score;

Bucket a review into a neg/neu/pos sentiment label.

SELECT nlp.main.sentiment_label('This was a terrible experience') AS mood;

Lemmatize an English string with the language pinned.

SELECT nlp.main.lemmatize('The cats were running', 'en') AS lemmas;
6 more examples

Canonicalize a messy string for dedup/matching.

SELECT nlp.main.normalize('  Café   DELUXE  ') AS canonical;

Extract named entities from a literal document, keyed back to its id.

SELECT id, ent_text, label
FROM nlp.main.entities((SELECT 1 AS id, 'Apple is based in California.' AS body), id := 'id', lang := 'en');
Result
id ent_text label
1 Apple ORG
1 California GPE

Split each review into sentences and score every sentence's sentiment to find the single most negative sentence per review -- pinpointing the complaint inside otherwise mixed feedback.

WITH reviews(id, body) AS (VALUES (1, 'The hotel location was perfect. The room was filthy and the staff were rude. Breakfast was fine.'), (2, 'Checkout was a frustrating mess. Otherwise it was a wonderful stay with a lovely view!')) SELECT id, arg_min(sentence, nlp.main.sentiment(sentence)) AS worst_sentence, round(min(nlp.main.sentiment(sentence)), 3) AS worst_score
FROM nlp.main.sentences((SELECT id, body FROM reviews), id := 'id', lang := 'en')
GROUP BY id
ORDER BY id;

Extract the organizations (ORG entities) mentioned in each review, join them back to their review by id, and average the review sentiment per organization -- brand perception from free text.

WITH reviews(id, body) AS (VALUES (1, 'I love my new Apple laptop, the battery life is amazing.'), (2, 'Microsoft support was awful and rude.'), (3, 'The Apple store staff were friendly and quick to help.'), (4, 'Microsoft keeps crashing my laptop, which is incredibly frustrating.')) SELECT e.ent_text AS organization, count(*) AS mentions, round(avg(nlp.main.sentiment(r.body)), 3) AS avg_sentiment
FROM nlp.main.entities((SELECT id, body FROM reviews), id := 'id', lang := 'en') AS e
JOIN reviews AS r USING (id)
WHERE e.label = 'ORG'
GROUP BY e.ent_text
ORDER BY avg_sentiment DESC;

Detect each document's language and look it up in the supported_languages table to see which default spaCy pipeline would process it -- documents in a language without one (here Swahili) get NULL and cannot be tokenized or run through NER without naming a model.

WITH docs(id, body) AS (VALUES (1, 'The quarterly report shows strong growth in every region.'), (2, 'Le rapport trimestriel montre une forte croissance dans toutes les régions.'), (3, 'Ripoti ya robo mwaka inaonyesha ukuaji mkubwa katika kila mkoa.')), detected AS (SELECT id, nlp.main.detect_lang(body) AS lang FROM docs) SELECT d.id, d.lang, s.spacy_model, s.spacy_model IS NOT NULL AS has_default_pipeline
FROM detected AS d
LEFT JOIN nlp.main.supported_languages AS s ON s.lang_code = d.lang
ORDER BY d.id;

Keep only reviews labelled negative, extract their noun chunks, and lemmatize each chunk's head noun so 'rooms' and 'room' count together -- ranking the aspects that negative reviews mention.

WITH reviews(id, body) AS (VALUES (1, 'The rooms were dirty and the beds were terrible.'), (2, 'Awful service, and the room smelled bad.'), (3, 'The beds were comfortable and the view was great.'), (4, 'The breakfast was cold and the coffee was disgusting.')) SELECT nlp.main.lemmatize(lower(root), 'en') AS aspect, count(DISTINCT id) AS negative_reviews
FROM nlp.main.noun_chunks((SELECT id, body FROM reviews WHERE nlp.main.sentiment_label(body) = 'neg'), id := 'id', lang := 'en')
GROUP BY aspect
ORDER BY negative_reviews DESC, aspect;
Tables
supported_languages 4 examples2 cols

Languages with a default spaCy pipeline: (lang_code, spacy_model) -- discovery table.

Columns
lang_code VARCHAR
ISO-639 language code accepted by the `lang` argument.
spacy_modelnot null VARCHAR
Default small spaCy pipeline that backs this language.
ConstraintsPRIMARY KEY (lang_code)
Examples (4)

Count the languages that have a default spaCy pipeline.

SELECT count(*) AS n_languages FROM nlp.main.supported_languages;

Look up the default spaCy model for English.

SELECT spacy_model FROM nlp.main.supported_languages WHERE lang_code = 'en';
SELECT count(*) AS n_languages FROM nlp.main.supported_languages();
1 more example
SELECT spacy_model
FROM nlp.main.supported_languages()
WHERE lang_code = 'en';
Link
Scalar functions
detect_lang (text VARCHAR) 2 examples

Detect the dominant language of each text (ISO-639 code, fastText lid.176)

Arguments
text VARCHAR
Text column to identify
ReturnsVARCHAR
Examples (2)

Identify the language of a literal string

SELECT nlp.main.detect_lang('The quick brown fox jumps over the lazy dog') AS lang;

Detect each document's language and look it up in the supported_languages table to see which default spaCy pipeline would process it -- documents in a language without one (here Swahili) get NULL and cannot be tokenized or run through NER without naming a model.

WITH docs(id, body) AS (VALUES (1, 'The quarterly report shows strong growth in every region.'), (2, 'Le rapport trimestriel montre une forte croissance dans toutes les régions.'), (3, 'Ripoti ya robo mwaka inaonyesha ukuaji mkubwa katika kila mkoa.')), detected AS (SELECT id, nlp.main.detect_lang(body) AS lang FROM docs) SELECT d.id, d.lang, s.spacy_model, s.spacy_model IS NOT NULL AS has_default_pipeline
FROM detected AS d
LEFT JOIN nlp.main.supported_languages AS s ON s.lang_code = d.lang
ORDER BY d.id;
Link
detect_lang_conf (text VARCHAR) 1 example

Confidence (0-1) of the detected language (fastText lid.176)

Arguments
text VARCHAR
Text column to identify
ReturnsFLOAT
Example

Confidence of the top language guess for a literal string

SELECT nlp.main.detect_lang_conf('The quick brown fox') AS conf;
Link
lemmatize (text VARCHAR, lang VARCHAR, model VARCHAR) +2 overloads 3 examples

Lemmatize each text (tokens replaced by their dictionary form); language auto-detected

Arguments
text VARCHAR
Text column to lemmatize
lang VARCHAR
Pipeline language (ISO-639), e.g. 'en'
model VARCHAR
spaCy model name, e.g. 'en_core_web_trf'
Overloads
lemmatize(text VARCHAR) → VARCHARlemmatize(text VARCHAR, lang VARCHAR) → VARCHARlemmatize(text VARCHAR, lang VARCHAR, model VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (3)

Lemmatize a literal string with per-row language auto-detect

SELECT nlp.main.lemmatize('The cats were running quickly') AS lemmas;

Lemmatize a literal string with the language pinned to English

SELECT nlp.main.lemmatize('The cats were running quickly', 'en') AS lemmas;

Lemmatize a literal string with an explicit spaCy model

SELECT nlp.main.lemmatize('The cats were running quickly', 'en', 'en_core_web_sm') AS lemmas;
Link
normalize (text VARCHAR) 1 example

Normalize text: Unicode NFKC, lowercase, and collapse whitespace

Arguments
text VARCHAR
Text column to normalize
ReturnsVARCHAR
Example

Canonicalize a messy literal string for dedup / matching

SELECT nlp.main.normalize('  Café   DELUXE	—  ') AS canonical;
Link
sentiment (text VARCHAR) 1 example

Sentiment score in [-1, 1] (VADER lexicon; tuned for English/social text)

Arguments
text VARCHAR
Text column to score
ReturnsFLOAT
Example

Score the sentiment of a literal English string

SELECT nlp.main.sentiment('I absolutely love this, it is fantastic!') AS score;
Link
sentiment_label (text VARCHAR) 1 example

Coarse sentiment label: neg / neu / pos (VADER thresholds)

Arguments
text VARCHAR
Text column to label
ReturnsVARCHAR
Example

Bucket a literal string into neg / neu / pos

SELECT nlp.main.sentiment_label('This is the worst experience ever') AS mood;
Link
strip_stopwords (text VARCHAR, lang VARCHAR, model VARCHAR) +2 overloads 3 examples

Remove stop-words and punctuation, returning the rest joined; language auto-detected

Arguments
text VARCHAR
Text column to clean
lang VARCHAR
Pipeline language (ISO-639); '' = ignore when model is set
model VARCHAR
spaCy model name, e.g. 'en_core_web_trf'
Overloads
strip_stopwords(text VARCHAR) → VARCHARstrip_stopwords(text VARCHAR, lang VARCHAR) → VARCHARstrip_stopwords(text VARCHAR, lang VARCHAR, model VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (3)

Drop stop-words from a literal string with per-row auto-detect

SELECT nlp.main.strip_stopwords('this is a really great movie') AS kept;

Drop English stop-words from a literal string

SELECT nlp.main.strip_stopwords('this is a really great movie', 'en') AS kept;

Drop stop-words from a literal string with an explicit spaCy model

SELECT nlp.main.strip_stopwords('this is a really great movie', 'en', 'en_core_web_sm') AS kept;
Link
Table in-out functions
entities (data TABLE, id := VARCHAR, lang := VARCHAR, model := VARCHAR, text := VARCHAR) 6 examples

Named entities per text row: (id, ent_text, label, start_char, end_char)

Positional arguments
data TABLE
Input relation (a (SELECT ...) subquery)
Named arguments
id := VARCHAR
Passthrough column copied onto every emitted row · default ""
lang := VARCHAR
Pipeline language (ISO-639); '' = auto-detect per row · default ""
model := VARCHAR
Override spaCy model name; '' = default for lang · default ""
text := VARCHAR
Text column name; default = the sole/first non-id column · default ""
Returns columns
ent_text VARCHAR
The entity span text.
label VARCHAR
Entity type (`PERSON`, `ORG`, `GPE`, `DATE`, `MONEY`, ...).
start_char INTEGER
Start character offset within the source text.
end_char INTEGER
End character offset within the source text.
Examples (6)

Explode a literal English document into entities, projecting its key columns

SELECT ent_text, label
FROM nlp.main.entities((SELECT 'Apple was founded by Steve Jobs in California.' AS body), lang := 'en');

Extract the organizations (ORG entities) mentioned in each review, join them back to their review by id, and average the review sentiment per organization -- brand perception from free text.

WITH reviews(id, body) AS (VALUES (1, 'I love my new Apple laptop, the battery life is amazing.'), (2, 'Microsoft support was awful and rude.'), (3, 'The Apple store staff were friendly and quick to help.'), (4, 'Microsoft keeps crashing my laptop, which is incredibly frustrating.')) SELECT e.ent_text AS organization, count(*) AS mentions, round(avg(nlp.main.sentiment(r.body)), 3) AS avg_sentiment
FROM nlp.main.entities((SELECT id, body FROM reviews), id := 'id', lang := 'en') AS e
JOIN reviews AS r USING (id)
WHERE e.label = 'ORG'
GROUP BY e.ent_text
ORDER BY avg_sentiment DESC;
SELECT id, ent_text, label
FROM nlp.main.entities((SELECT 1 AS id, 'Apple was founded by Steve Jobs in California.' AS body), id := 'id', lang := 'en');
3 more examples
SELECT id, token, pos
FROM nlp.main.tokens((SELECT 1 AS id, 'The quick brown fox jumps.' AS body), id := 'id', lang := 'en');
SELECT id, sent_index, sentence
FROM nlp.main.sentences((SELECT 1 AS id, 'First sentence here. Second one follows.' AS body), id := 'id', lang := 'en');
SELECT id, chunk, root
FROM nlp.main.noun_chunks((SELECT 1 AS id, 'The big red car drove down the long road.' AS body), id := 'id', lang := 'en');
Link
noun_chunks (data TABLE, id := VARCHAR, lang := VARCHAR, model := VARCHAR, text := VARCHAR) 2 examples

Noun chunks per text row: (id, chunk, root) -- keyword/topic candidates

Positional arguments
data TABLE
Input relation (a (SELECT ...) subquery)
Named arguments
id := VARCHAR
Passthrough column copied onto every emitted row · default ""
lang := VARCHAR
Pipeline language (ISO-639); '' = auto-detect per row · default ""
model := VARCHAR
Override spaCy model name; '' = default for lang · default ""
text := VARCHAR
Text column name; default = the sole/first non-id column · default ""
Returns columns
chunk VARCHAR
The noun-phrase text.
root VARCHAR
The head/root token of the noun phrase.
Examples (2)

Explode a literal English document into noun_chunks, projecting its key columns

SELECT chunk, root
FROM nlp.main.noun_chunks((SELECT 'The big red car drove down the long road.' AS body), lang := 'en');

Keep only reviews labelled negative, extract their noun chunks, and lemmatize each chunk's head noun so 'rooms' and 'room' count together -- ranking the aspects that negative reviews mention.

WITH reviews(id, body) AS (VALUES (1, 'The rooms were dirty and the beds were terrible.'), (2, 'Awful service, and the room smelled bad.'), (3, 'The beds were comfortable and the view was great.'), (4, 'The breakfast was cold and the coffee was disgusting.')) SELECT nlp.main.lemmatize(lower(root), 'en') AS aspect, count(DISTINCT id) AS negative_reviews
FROM nlp.main.noun_chunks((SELECT id, body FROM reviews WHERE nlp.main.sentiment_label(body) = 'neg'), id := 'id', lang := 'en')
GROUP BY aspect
ORDER BY negative_reviews DESC, aspect;
Link
sentences (data TABLE, id := VARCHAR, lang := VARCHAR, model := VARCHAR, text := VARCHAR) 2 examples

Sentences per text row: (id, sent_index, sentence) -- chunking for embeddings

Positional arguments
data TABLE
Input relation (a (SELECT ...) subquery)
Named arguments
id := VARCHAR
Passthrough column copied onto every emitted row · default ""
lang := VARCHAR
Pipeline language (ISO-639); '' = auto-detect per row · default ""
model := VARCHAR
Override spaCy model name; '' = default for lang · default ""
text := VARCHAR
Text column name; default = the sole/first non-id column · default ""
Returns columns
sent_index INTEGER
0-based index of the sentence within the source text.
sentence VARCHAR
The sentence text.
Examples (2)

Explode a literal English document into sentences, projecting its key columns

SELECT sent_index, sentence
FROM nlp.main.sentences((SELECT 'First sentence here. Second one follows.' AS body), lang := 'en');

Split each review into sentences and score every sentence's sentiment to find the single most negative sentence per review -- pinpointing the complaint inside otherwise mixed feedback.

WITH reviews(id, body) AS (VALUES (1, 'The hotel location was perfect. The room was filthy and the staff were rude. Breakfast was fine.'), (2, 'Checkout was a frustrating mess. Otherwise it was a wonderful stay with a lovely view!')) SELECT id, arg_min(sentence, nlp.main.sentiment(sentence)) AS worst_sentence, round(min(nlp.main.sentiment(sentence)), 3) AS worst_score
FROM nlp.main.sentences((SELECT id, body FROM reviews), id := 'id', lang := 'en')
GROUP BY id
ORDER BY id;
Link
tokens (data TABLE, id := VARCHAR, lang := VARCHAR, model := VARCHAR, text := VARCHAR) 1 example

Tokens per text row: (id, token, lemma, pos, tag, is_stop, dep)

Positional arguments
data TABLE
Input relation (a (SELECT ...) subquery)
Named arguments
id := VARCHAR
Passthrough column copied onto every emitted row · default ""
lang := VARCHAR
Pipeline language (ISO-639); '' = auto-detect per row · default ""
model := VARCHAR
Override spaCy model name; '' = default for lang · default ""
text := VARCHAR
Text column name; default = the sole/first non-id column · default ""
Returns columns
token VARCHAR
The token text.
lemma VARCHAR
The token's lemma (dictionary form).
pos VARCHAR
Coarse universal part-of-speech tag.
tag VARCHAR
Fine-grained part-of-speech tag.
is_stop BOOLEAN
Whether the token is a stop-word.
dep VARCHAR
Syntactic dependency relation.
Example

Explode a literal English document into tokens, projecting its key columns

SELECT token, pos
FROM nlp.main.tokens((SELECT 'The quick brown fox jumps.' AS body), lang := 'en');
Link

Try these queries

Detect the language of a French string.

SELECT nlp.main.detect_lang('Bonjour tout le monde') AS lang

Uses detect_lang

Score the sentiment of a positive English review.

SELECT nlp.main.sentiment('I absolutely love this product!') AS score

Uses sentiment

Bucket a review into a neg/neu/pos sentiment label.

SELECT nlp.main.sentiment_label('This was a terrible experience') AS mood

Uses sentiment_label

Lemmatize an English string with the language pinned.

SELECT nlp.main.lemmatize('The cats were running', 'en') AS lemmas

Uses lemmatize

Canonicalize a messy string for dedup/matching.

SELECT nlp.main.normalize('  Café   DELUXE  ') AS canonical

Uses normalize

Count the languages that have a default spaCy pipeline.

SELECT count(*) AS n_languages FROM nlp.main.supported_languages

Uses supported_languages

26 more examples in the Catalog, each listed under the table or function it uses.

NLP is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.