| Title: | DuckDB-Native Semantic Graph Grounding |
|---|---|
| Description: | DuckDB-native semantic graph grounding over arbitrary concept graphs. The package owns graph schema creation, alias indexing, lexical mention grounding, transitive graph closure, 'EmbeddingGemma' dense retrieval, 'ColBERT' late interaction, and 'BebeLM' judgment prompts. HPO, MONDO, ORPHANET, memory graphs, and run ledgers are graph sources, not special package APIs. |
| Authors: | Sounkou Mahamane Toure [aut, cre], Human Phenotype Ontology [cph] (Bundled README fixture (CC BY 4.0)) |
| Maintainer: | Sounkou Mahamane Toure <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-21 19:31:55 UTC |
| Source: | https://github.com/RGenomicsETL/ducksemantics |
Annotate text against the semantic alias index
ducksemantics_annotate( conn, text, document_id = NULL, prefix = "semantic", longest_match = TRUE, record = FALSE )ducksemantics_annotate( conn, text, document_id = NULL, prefix = "semantic", longest_match = TRUE, record = FALSE )
conn |
DBI connection. |
text |
Character scalar. |
document_id |
Optional document id. |
prefix |
Prefix used for semantic tables. |
longest_match |
Drop matches contained by a longer span. |
record |
Append returned mentions to the mentions table? |
A data frame of grounded mentions.
Judge mentions with a BebeLM/Rbebelm agent
ducksemantics_bebel_judge( agent, text, mentions, conn = NULL, prefix = "semantic", graph_context = NULL, instructions = ducksemantics_default_judgment_instructions(), parser = ducksemantics_json_judgment_parser(), on_event = NULL, max_retries = 1L, record = !is.null(conn), model = "Rbebelm" )ducksemantics_bebel_judge( agent, text, mentions, conn = NULL, prefix = "semantic", graph_context = NULL, instructions = ducksemantics_default_judgment_instructions(), parser = ducksemantics_json_judgment_parser(), on_event = NULL, max_retries = 1L, record = !is.null(conn), model = "Rbebelm" )
agent |
A |
text |
Source text. |
mentions |
Mention data frame from |
conn |
Optional DBI connection. When supplied with |
prefix |
Prefix used for semantic tables. |
graph_context |
Optional data frame or list with nearby graph context. |
instructions |
Character scalar or vector containing the adjudication policy. |
parser |
Object implementing DucksemanticsJudgmentParser. |
on_event |
Optional Rbebelm event handler. |
max_retries |
Number of corrective turns after a response fails the
strict |
record |
Append judgments to the judgment table? |
model |
Model label recorded with judgments. |
A data frame of judgment rows. Its responses and parse_errors
attributes retain every model response and corrective parse error.
Create a BebeLM prompt runner
ducksemantics_bebel_runner(agent, on_event = NULL)ducksemantics_bebel_runner(agent, on_event = NULL)
agent |
A |
on_event |
Optional Rbebelm event handler. |
An object implementing DucksemanticsPromptRunner.
Create a BebeLM tool-call judgment parser
ducksemantics_bebel_tool_judgment_parser(tool_name = NULL)ducksemantics_bebel_tool_judgment_parser(tool_name = NULL)
tool_name |
Optional accepted tool-call name or names. |
An object implementing DucksemanticsJudgmentParser.
Run a grounding benchmark
ducksemantics_benchmark( benchmark, conn, prefix = "semantic", annotator = ducksemantics_lexical_annotator(), longest_match = TRUE, record = FALSE, collect_index_stats = TRUE )ducksemantics_benchmark( benchmark, conn, prefix = "semantic", annotator = ducksemantics_lexical_annotator(), longest_match = TRUE, record = FALSE, collect_index_stats = TRUE )
benchmark |
Benchmark object from |
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
annotator |
Object implementing DucksemanticsAnnotator. |
longest_match |
Drop matches contained by a longer span. |
record |
Append predicted mentions to the mentions table? |
collect_index_stats |
Include index stats in the result? |
A list with predictions, timings, metrics, and optional index stats.
Define benchmark cases
ducksemantics_benchmark_cases( cases, gold, suite = "semantic", task = "grounding", source = NULL, version = NULL, metadata = list() )ducksemantics_benchmark_cases( cases, gold, suite = "semantic", task = "grounding", source = NULL, version = NULL, metadata = list() )
cases |
Data frame with |
gold |
Data frame with |
suite |
Benchmark suite label. |
task |
Benchmark task label. |
source |
Optional source dataset label. |
version |
Optional source dataset version. |
metadata |
Optional named list of benchmark metadata. |
A benchmark object.
Compute benchmark precision and recall
ducksemantics_benchmark_metrics(predictions, gold, by = c("node", "span"))ducksemantics_benchmark_metrics(predictions, gold, by = c("node", "span"))
predictions |
Prediction data frame from |
gold |
Gold data frame with |
by |
Match on |
A one-row data frame with tp, fp, fn, precision, recall,
and f1.
Cache a source file
ducksemantics_cache_file( url, filename = basename(url), cache_dir = tools::R_user_dir("ducksemantics", "cache"), refresh = FALSE )ducksemantics_cache_file( url, filename = basename(url), cache_dir = tools::R_user_dir("ducksemantics", "cache"), refresh = FALSE )
url |
Source URL. |
filename |
Cache filename. |
cache_dir |
Cache directory. |
refresh |
Download even when the cache file already exists? |
Normalized path to the cached file.
Cache an R value on disk
ducksemantics_cache_rds(path, compute, refresh = FALSE)ducksemantics_cache_rds(path, compute, refresh = FALSE)
path |
RDS cache path. |
compute |
Function called with no arguments when the cache is missing or refreshed. |
refresh |
Recompute even when the cache file already exists? |
The cached R object.
Returns DuckDB SQL that computes target_table(from_id, predicate, to_id) as
the transitive closure of source_table for the supplied predicates. This is
the same graph-as-SQL primitive used for ontology ancestors, partonomy,
memory walks, and arbitrary declared transitive graph relations.
ducksemantics_closure_sql( transitive_predicates, source_table = "semantic_edges", target_table = "semantic_entailed_edges" )ducksemantics_closure_sql( transitive_predicates, source_table = "semantic_edges", target_table = "semantic_entailed_edges" )
transitive_predicates |
Character vector of predicates to close. |
source_table |
Source edge table. |
target_table |
Target closure table. |
A DuckDB SQL script that replaces the closure table and restores its graph indexes.
Clustering writes assignments and centroids back to DuckDB. It is intended as a first measurement surface for whether a provider's embeddings recover ontology structure before adding graph-aware or late-interaction scoring.
ducksemantics_cluster_embeddings( spec, conn, prefix = "semantic", replace = TRUE )ducksemantics_cluster_embeddings( spec, conn, prefix = "semantic", replace = TRUE )
spec |
A |
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
replace |
Delete rows for |
A list with assignments, centroids, summary, and the kmeans object.
role = "document" is for ontology labels, definitions, and candidate
passages stored in DuckDB. role = "query" is for text being searched. The
native encoder owns the distinct prefixes, token limits, projection, and L2
normalization required by the model; no causal BebeLM hidden states are used.
ducksemantics_colbert_provider( model, role = c("document", "query"), label = "Rbebelm ColBERT" )ducksemantics_colbert_provider( model, role = c("document", "query"), label = "Rbebelm ColBERT" )
model |
A |
role |
Whether this provider encodes retrieval |
label |
Provider label. Document rows and their query must share it. |
An object implementing DucksemanticsTokenEmbeddingProvider.
Encodes text with the profile's query contract and returns a query object
directly consumable by ducksemantics_late_interaction_search(). Candidate
blocks must have been stored from a ColBERT document provider with the same
label.
ducksemantics_colbert_query( model, text, provider = "Rbebelm ColBERT", subject_kind = NULL, top_k = 10L, table = NULL, candidate_subject_id = NULL )ducksemantics_colbert_query( model, text, provider = "Rbebelm ColBERT", subject_kind = NULL, top_k = 10L, table = NULL, candidate_subject_id = NULL )
model |
A |
text |
Non-empty query text. |
provider |
Stored document provider label. |
subject_kind |
Optional candidate subject-kind filter. |
top_k |
Number of candidate blocks to return. |
table |
Optional token-embedding table. |
candidate_subject_id |
Optional candidate subject identifiers. |
A DucksemanticsTokenEmbeddingQuery.
Connect to a DuckDB semantic store
ducksemantics_connect(dbdir = ":memory:", read_only = FALSE, array = "matrix")ducksemantics_connect(dbdir = ":memory:", read_only = FALSE, array = "matrix")
dbdir |
DuckDB database path, or |
read_only |
Open read-only? |
array |
DuckDB array conversion mode. The default enables native vector columns to round-trip through R matrices. |
A DBI connection.
These are only the default policy for the judgment prompt. Pass an explicit
instruction string to ducksemantics_judgment_prompt() or
ducksemantics_judge() when benchmarking a specific adjudication protocol.
ducksemantics_default_judgment_instructions()ducksemantics_default_judgment_instructions()
A character scalar.
This cache is used for large ontology passes. Each chunk is written after it finishes, so interrupted runs can resume without discarding completed native retrieval-encoder work.
ducksemantics_embed_cached( text, provider, cache_dir, chunk_size = 4096L, refresh = FALSE, cache_key = NULL, ... )ducksemantics_embed_cached( text, provider, cache_dir, chunk_size = 4096L, refresh = FALSE, cache_key = NULL, ... )
text |
Character vector to embed. |
provider |
Object implementing DucksemanticsEmbeddingProvider. |
cache_dir |
Directory for chunk RDS files. |
chunk_size |
Number of texts per persisted chunk. |
refresh |
Recompute all chunks? |
cache_key |
Optional stable identifier for provider weights or other state that is not represented by the provider object. Changing it invalidates existing chunks. |
... |
Extra arguments passed to |
Numeric embedding matrix with one row per input text.
Construct an embedding batch
ducksemantics_embedding_batch( embeddings, subject_id, subject_kind = "node", provider = "embedding", text = NULL, attrs = NULL )ducksemantics_embedding_batch( embeddings, subject_id, subject_kind = "node", provider = "embedding", text = NULL, attrs = NULL )
embeddings |
Numeric matrix with one row per subject. |
subject_id |
Subject identifiers matching embedding rows. |
subject_kind |
Subject type, e.g. |
provider |
Embedding provider label. |
text |
Optional source text for each embedding. |
attrs |
Optional JSON text or other metadata for each embedding. |
This measures whether clustered node embeddings respect direct ontology
relations such as is_a and part_of. It is a coarse diagnostic: high
agreement does not prove semantic quality, but low agreement is actionable
evidence for the embedding, text source, or clustering setup.
ducksemantics_embedding_cluster_graph_agreement( conn, cluster_run_id, predicates = c("is_a", "part_of"), prefix = "semantic" )ducksemantics_embedding_cluster_graph_agreement( conn, cluster_run_id, predicates = c("is_a", "part_of"), prefix = "semantic" )
conn |
DBI connection. |
cluster_run_id |
Cluster run id written by
|
predicates |
Edge predicates to evaluate. |
prefix |
Prefix used for semantic tables. |
One-row data frame with edge counts and same-cluster rate.
Construct an embedding clustering specification
ducksemantics_embedding_cluster_spec( k, provider = NULL, subject_kind = NULL, dimensions = NULL, table = NULL, run_id = NULL, seed = 1L, nstart = 10L, max_iter = 100L )ducksemantics_embedding_cluster_spec( k, provider = NULL, subject_kind = NULL, dimensions = NULL, table = NULL, run_id = NULL, seed = 1L, nstart = 10L, max_iter = 100L )
k |
Number of clusters. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
dimensions |
Optional embedding dimension filter. |
table |
Optional embedding table. Defaults to |
run_id |
Identifier written to cluster tables. |
seed |
Random seed used by |
nstart |
Number of starts used by |
max_iter |
Maximum k-means iterations. |
Summarize stored embedding clusters
ducksemantics_embedding_cluster_summary( conn, cluster_run_id = NULL, prefix = "semantic" )ducksemantics_embedding_cluster_summary( conn, cluster_run_id = NULL, prefix = "semantic" )
conn |
DBI connection. |
cluster_run_id |
Optional cluster run filter. |
prefix |
Prefix used for semantic tables. |
Data frame with cluster sizes and distance summaries.
Construct an embedding index specification
ducksemantics_embedding_index_spec( dimensions, provider = NULL, subject_kind = NULL, table = NULL, hnsw = TRUE, metric = "cosine", load_vss = TRUE )ducksemantics_embedding_index_spec( dimensions, provider = NULL, subject_kind = NULL, table = NULL, hnsw = TRUE, metric = "cosine", load_vss = TRUE )
dimensions |
Embedding dimension. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
table |
Target table name. Defaults to
|
hnsw |
Create a DuckDB HNSW index on the materialized table? |
metric |
HNSW metric, usually |
load_vss |
Load DuckDB's |
Wrap an embedding function as a typed embedding provider
ducksemantics_embedding_provider(fun, label = "function")ducksemantics_embedding_provider(fun, label = "function")
fun |
Function accepting a character vector and returning a numeric matrix with one row per input text. |
label |
Provider label for reports. |
An object implementing DucksemanticsEmbeddingProvider.
Construct an embedding search query
ducksemantics_embedding_query( embedding, provider = NULL, subject_kind = NULL, top_k = 10L, metric = c("cosine", "cosine_distance", "l2", "inner_product"), table = NULL )ducksemantics_embedding_query( embedding, provider = NULL, subject_kind = NULL, top_k = 10L, metric = c("cosine", "cosine_distance", "l2", "inner_product"), table = NULL )
embedding |
Numeric query embedding. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
top_k |
Number of nearest rows to return. |
metric |
One of |
table |
Optional table to search. Defaults to |
Search embeddings with DuckDB vector functions
ducksemantics_embedding_search(query, conn, prefix = "semantic")ducksemantics_embedding_search(query, conn, prefix = "semantic")
query |
A DucksemanticsEmbeddingQuery object from
|
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
Data frame ordered by best match.
Create an EmbeddingGemma dense retrieval provider
ducksemantics_embeddinggemma_provider( model, label = "Rbebelm EmbeddingGemma", task = "semantic_similarity", title = NULL, dimensions = 768L, normalize = TRUE, truncate = TRUE, check_interrupt = TRUE )ducksemantics_embeddinggemma_provider( model, label = "Rbebelm EmbeddingGemma", task = "semantic_similarity", title = NULL, dimensions = 768L, normalize = TRUE, truncate = TRUE, check_interrupt = TRUE )
model |
A |
label |
Provider label for stored dense vectors. |
task |
EmbeddingGemma task prompt. Use the same task for vectors that will be compared; use the dedicated query/document tasks only as a matched retrieval pair. |
title |
Optional document title, valid only for |
dimensions |
Matryoshka dimension: 768, 512, 256, or 128. |
normalize |
L2-normalize output rows. |
truncate |
Truncate inputs longer than EmbeddingGemma's context. |
check_interrupt |
Poll for R interrupts between bounded native batches. |
An object implementing DucksemanticsEmbeddingProvider.
Build the lexical alias index
ducksemantics_index_aliases(conn, prefix = "semantic")ducksemantics_index_aliases(conn, prefix = "semantic")
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
Invisibly, the alias index table name.
Summarize semantic index size
ducksemantics_index_stats(conn, prefix = "semantic")ducksemantics_index_stats(conn, prefix = "semantic")
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
A list with table row counts and alias-index pressure metrics.
Initialize semantic graph tables
ducksemantics_init(conn, prefix = "semantic")ducksemantics_init(conn, prefix = "semantic")
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
Invisibly, conn.
Create the default JSON judgment parser
ducksemantics_json_judgment_parser()ducksemantics_json_judgment_parser()
An object implementing DucksemanticsJudgmentParser.
Judge mentions with a model runner
ducksemantics_judge( text, mentions, runner, conn = NULL, prefix = "semantic", graph_context = NULL, instructions = ducksemantics_default_judgment_instructions(), prompt_builder = ducksemantics_judgment_prompt, parser = ducksemantics_json_judgment_parser(), record = !is.null(conn), model = "semantic-runner", ... )ducksemantics_judge( text, mentions, runner, conn = NULL, prefix = "semantic", graph_context = NULL, instructions = ducksemantics_default_judgment_instructions(), prompt_builder = ducksemantics_judgment_prompt, parser = ducksemantics_json_judgment_parser(), record = !is.null(conn), model = "semantic-runner", ... )
text |
Source text. |
mentions |
Mention data frame from |
runner |
Object implementing DucksemanticsPromptRunner. |
conn |
Optional DBI connection. When supplied with |
prefix |
Prefix used for semantic tables. |
graph_context |
Optional data frame or list with nearby graph context. |
instructions |
Character scalar or vector containing the adjudication policy. |
prompt_builder |
Function that builds the prompt. |
parser |
Object implementing DucksemanticsJudgmentParser. |
record |
Append judgments to the judgment table? |
model |
Model label recorded with judgments. |
... |
Extra arguments passed to |
A data frame of judgment rows. The prompt and raw response are stored
as prompt and response attributes for audit and benchmarking.
Build a semantic judgment prompt
ducksemantics_judgment_prompt( text, mentions, graph_context = NULL, instructions = ducksemantics_default_judgment_instructions() )ducksemantics_judgment_prompt( text, mentions, graph_context = NULL, instructions = ducksemantics_default_judgment_instructions() )
text |
Source text. |
mentions |
Mention data frame from |
graph_context |
Optional data frame or list with nearby graph context. |
instructions |
Character scalar or vector containing the adjudication policy. This is deliberately explicit so benchmark runs can vary the policy without changing candidate generation. |
Prompt text.
Scores stored native ColBERT document blocks with exact MaxSim. For each
query token, the scorer finds the best matching document token and sums those
maxima, matching Rbebelm::colbert_maxsim() once both matrices have been
materialized. Use dense EmbeddingGemma/HNSW, aliases, FTS, or graph context
to reduce large corpora before this reranker.
ducksemantics_late_interaction_search(query, conn, prefix = "semantic")ducksemantics_late_interaction_search(query, conn, prefix = "semantic")
query |
A |
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
Data frame ordered by descending MaxSim score.
Create the default DuckDB lexical annotator
ducksemantics_lexical_annotator()ducksemantics_lexical_annotator()
An object implementing DucksemanticsAnnotator.
DuckDB's HNSW index requires a fixed-size vector type such as FLOAT[384].
This function projects rows from semantic_embeddings into a dimensioned
table and can create a native HNSW index on that table.
ducksemantics_materialize_embedding_index(spec, conn, prefix = "semantic")ducksemantics_materialize_embedding_index(spec, conn, prefix = "semantic")
spec |
A DucksemanticsEmbeddingIndexSpec object from
|
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
Target table name.
Normalize text for semantic grounding
ducksemantics_normalize(text)ducksemantics_normalize(text)
text |
Character vector. |
Normalized character vector.
This mirrors the graph projection profile used in pi-bio-agent: a source
table with caller-named columns becomes a stable graph edge table with
from_id, predicate, to_id, attrs, and trust.
ducksemantics_projection_sql( source_table, from, predicate, to, target_table = "semantic_edges", attrs = NULL, trust = NULL )ducksemantics_projection_sql( source_table, from, predicate, to, target_table = "semantic_edges", attrs = NULL, trust = NULL )
source_table |
Source table or view name. |
from, predicate, to
|
Source column names. |
target_table |
Target table name. |
attrs, trust
|
Optional source columns containing JSON text. |
A DuckDB SQL script that replaces the target table and restores its graph indexes.
Wrap a prompt function as a typed prompt runner
ducksemantics_prompt_runner(fun, label = "function")ducksemantics_prompt_runner(fun, label = "function")
fun |
Function accepting |
label |
Provider label for reports. |
An object implementing DucksemanticsPromptRunner.
These S7 generics are the behavior required by the structural interfaces.
Provider packages should define concrete S7 classes and methods for these
generics, then consuming code can assert the corresponding Ducksemantics*
interface.
ducksemantics_run(provider, prompt, ...) ducksemantics_embed(provider, text, ...) ducksemantics_token_embed(provider, text, ...) ducksemantics_parse(parser, response, ...) ducksemantics_ground( annotator, conn, text, document_id = NULL, prefix = "semantic", longest_match = TRUE, record = FALSE, ... )ducksemantics_run(provider, prompt, ...) ducksemantics_embed(provider, text, ...) ducksemantics_token_embed(provider, text, ...) ducksemantics_parse(parser, response, ...) ducksemantics_ground( annotator, conn, text, document_id = NULL, prefix = "semantic", longest_match = TRUE, record = FALSE, ... )
provider |
Prompt or embedding provider. |
prompt |
Prompt text. |
... |
Provider-specific arguments. |
text |
Source text. |
parser |
Judgment parser. |
response |
Raw model response text. |
annotator |
Text-grounding provider. |
conn |
DBI connection. |
document_id |
Optional document id. |
prefix |
Semantic table prefix. |
longest_match |
Drop matches contained by a longer span. |
record |
Append returned rows to the semantic store? |
Provider-specific output: response text, embedding matrix, parsed judgment data frame, or grounded mention data frame.
Read an OBO ontology into semantic graph rows
ducksemantics_read_obo( path, family, source = basename(path), include_obsolete = FALSE )ducksemantics_read_obo( path, family, source = basename(path), include_obsolete = FALSE )
path |
OBO file path. |
family |
Graph family label, for example |
source |
Source label stored on alias rows. |
include_obsolete |
Include terms marked |
A list with nodes, aliases, and edges data frames.
Record semantic judgments
ducksemantics_record_judgments(conn, judgments, prefix = "semantic")ducksemantics_record_judgments(conn, judgments, prefix = "semantic")
conn |
DBI connection. |
judgments |
Judgment data frame. |
prefix |
Prefix used for semantic tables. |
Invisibly, judgments.
Returns the core SQL DDL for the generic semantic graph and grounding contract. The schema is intentionally not HPO-specific: ontology terms, local concept graphs, memory nodes, and pi-bio-agent graph projections can all use the same node, alias, edge, mention, and judgment tables.
ducksemantics_schema_sql(prefix = "semantic")ducksemantics_schema_sql(prefix = "semantic")
prefix |
Prefix used for the generated table names. |
A character vector of SQL statements.
Semantic graph table names
ducksemantics_tables(prefix = "semantic")ducksemantics_tables(prefix = "semantic")
prefix |
Prefix used for generated table names. |
A named character vector.
Construct a token embedding batch
ducksemantics_token_embedding_batch( embeddings, subject_id, subject_kind = "node", provider = "embedding", token_index = NULL, block_id = NULL, token = NULL, start_offset = NULL, end_offset = NULL, attrs = NULL )ducksemantics_token_embedding_batch( embeddings, subject_id, subject_kind = "node", provider = "embedding", token_index = NULL, block_id = NULL, token = NULL, start_offset = NULL, end_offset = NULL, attrs = NULL )
embeddings |
Numeric matrix with one row per token. |
subject_id |
Subject identifier for each token row. |
subject_kind |
Subject type, e.g. |
provider |
Embedding provider label. |
token_index |
Token index within each subject block. Defaults to
zero-based order within |
block_id |
Matrix/block identifier. Defaults to one block per
|
token |
Optional token text for each row. |
start_offset, end_offset
|
Optional zero-based source offsets. |
attrs |
Optional JSON text or other metadata for each token row. |
Construct a token embedding batch from a provider
ducksemantics_token_embedding_batch_from_provider( text, provider, subject_id = text, subject_kind = "node", provider_label = NULL, block_id = NULL, attrs = NULL, ... )ducksemantics_token_embedding_batch_from_provider( text, provider, subject_id = text, subject_kind = "node", provider_label = NULL, block_id = NULL, attrs = NULL, ... )
text |
Character vector to embed. |
provider |
Object implementing |
subject_id |
Subject identifiers for input texts. Defaults to |
subject_kind |
Subject type for stored token rows. |
provider_label |
Stored provider label. Defaults to the provider label when available. |
block_id |
Optional block id per input text. |
attrs |
Optional attrs value per input text. |
... |
Extra arguments passed to |
A DucksemanticsTokenEmbeddingBatch object.
Wrap a token embedding function as a typed token provider
ducksemantics_token_embedding_provider(fun, label = "function-token")ducksemantics_token_embedding_provider(fun, label = "function-token")
fun |
Function accepting a character vector and returning one token-embedding object per input text. |
label |
Provider label for stored token rows. |
An object implementing DucksemanticsTokenEmbeddingProvider.
Construct a token embedding late-interaction query
ducksemantics_token_embedding_query( embeddings, provider = NULL, subject_kind = NULL, top_k = 10L, table = NULL, candidate_subject_id = NULL )ducksemantics_token_embedding_query( embeddings, provider = NULL, subject_kind = NULL, top_k = 10L, table = NULL, candidate_subject_id = NULL )
embeddings |
Numeric query-token matrix. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
top_k |
Number of scored blocks to return. |
table |
Optional table to search. Defaults to |
candidate_subject_id |
Optional candidate subject identifiers. |
Tokenize text for semantic grounding
ducksemantics_tokens(text)ducksemantics_tokens(text)
text |
Character scalar. |
A data frame with token text, normalized token text, zero-based start offset, end offset, and token index.
Embeddings are stored in DuckDB as native FLOAT[] vectors. Similarity search
casts those vectors to fixed-size FLOAT[N] arrays so DuckDB's vector
functions and optional HNSW index can be used directly.
ducksemantics_write_embeddings( batch, conn, prefix = "semantic", replace = FALSE )ducksemantics_write_embeddings( batch, conn, prefix = "semantic", replace = FALSE )
batch |
A DucksemanticsEmbeddingBatch object from
|
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
replace |
Delete existing embeddings for the same subjects and provider before inserting? |
Invisibly, the written embedding rows.
Write graph rows into the semantic store
ducksemantics_write_graph( conn, nodes = NULL, aliases = NULL, edges = NULL, prefix = "semantic", replace = FALSE, index = TRUE )ducksemantics_write_graph( conn, nodes = NULL, aliases = NULL, edges = NULL, prefix = "semantic", replace = FALSE, index = TRUE )
conn |
DBI connection. |
nodes |
Data frame with |
aliases |
Data frame with |
edges |
Data frame with |
prefix |
Prefix used for semantic tables. |
replace |
Delete existing rows from populated target tables before writing? |
index |
Rebuild the alias index after writing aliases? |
Invisibly, the semantic table names.
Write an OBO ontology into the semantic store
ducksemantics_write_obo( conn, path, family, source = basename(path), prefix = "semantic", replace = FALSE, index = TRUE, include_obsolete = FALSE )ducksemantics_write_obo( conn, path, family, source = basename(path), prefix = "semantic", replace = FALSE, index = TRUE, include_obsolete = FALSE )
conn |
DBI connection. |
path |
OBO file path. |
family |
Graph family label, for example |
source |
Source label stored on alias rows. |
prefix |
Prefix used for semantic tables. |
replace |
Delete existing graph rows before writing? |
index |
Rebuild the alias index? |
include_obsolete |
Include terms marked |
The parsed graph rows, invisibly.
Native ColBERT document vectors are grouped by block_id, so exact MaxSim
can compare a query-token matrix to a stored candidate matrix without
changing the graph schema. Dense vectors in semantic_embeddings remain the
inexpensive broad-retrieval layer.
ducksemantics_write_token_embeddings( batch, conn, prefix = "semantic", replace = FALSE )ducksemantics_write_token_embeddings( batch, conn, prefix = "semantic", replace = FALSE )
batch |
A |
conn |
DBI connection. |
prefix |
Prefix used for semantic tables. |
replace |
Delete existing token rows for the same subjects and provider before inserting? |
Invisibly, the written token embedding rows.
An annotator grounds text against the semantic store and returns mention rows. The default implementation is the DuckDB lexical alias index.
DucksemanticsAnnotatorDucksemanticsAnnotator
S7 value object for a valid DBI connection.
DucksemanticsDbConnection(value = NULL)DucksemanticsDbConnection(value = NULL)
value |
DBI connection. |
A DucksemanticsDbConnection object.
Embedding batch for the semantic store
DucksemanticsEmbeddingBatch( embeddings = integer(0), subject_id = character(0), subject_kind = character(0), provider = character(0), text = NULL, attrs = NULL )DucksemanticsEmbeddingBatch( embeddings = integer(0), subject_id = character(0), subject_kind = character(0), provider = character(0), text = NULL, attrs = NULL )
embeddings |
Numeric matrix with one row per subject. |
subject_id |
Subject identifiers matching embedding rows. |
subject_kind |
Subject type, e.g. |
provider |
Embedding provider label. |
text |
Optional source text for each embedding. |
attrs |
Optional JSON text or other metadata for each embedding. |
A DucksemanticsEmbeddingBatch object.
Embedding clustering specification
DucksemanticsEmbeddingClusterSpec( k = integer(0), provider = NULL, subject_kind = NULL, dimensions = NULL, table = NULL, run_id = character(0), seed = integer(0), nstart = integer(0), max_iter = integer(0) )DucksemanticsEmbeddingClusterSpec( k = integer(0), provider = NULL, subject_kind = NULL, dimensions = NULL, table = NULL, run_id = character(0), seed = integer(0), nstart = integer(0), max_iter = integer(0) )
k |
Number of clusters. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
dimensions |
Optional embedding dimension filter. |
table |
Optional embedding table. Defaults to |
run_id |
Identifier written to cluster tables. |
seed |
Random seed used by |
nstart |
Number of starts used by |
max_iter |
Maximum k-means iterations. |
Clustering always materializes an ordinary finite R matrix from the
DuckDB FLOAT[] rows.
A DucksemanticsEmbeddingClusterSpec object.
Embedding index specification
DucksemanticsEmbeddingIndexSpec( dimensions = integer(0), provider = NULL, subject_kind = NULL, table = NULL, hnsw = logical(0), metric = character(0), load_vss = logical(0) )DucksemanticsEmbeddingIndexSpec( dimensions = integer(0), provider = NULL, subject_kind = NULL, table = NULL, hnsw = logical(0), metric = character(0), load_vss = logical(0) )
dimensions |
Embedding dimension. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
table |
Target table name. Defaults to
|
hnsw |
Create a DuckDB HNSW index on the materialized table? |
metric |
HNSW metric, usually |
load_vss |
Load DuckDB's |
A DucksemanticsEmbeddingIndexSpec object.
S7 value object for a finite numeric embedding matrix with an expected row count.
DucksemanticsEmbeddingMatrix(embeddings = integer(0), rows = integer(0))DucksemanticsEmbeddingMatrix(embeddings = integer(0), rows = integer(0))
embeddings |
Numeric matrix. |
rows |
Expected number of matrix rows. |
A DucksemanticsEmbeddingMatrix object.
An embedding provider accepts a character vector and returns a numeric matrix with one row per input text.
DucksemanticsEmbeddingProviderDucksemanticsEmbeddingProvider
Embedding search query
DucksemanticsEmbeddingQuery( embedding = integer(0), provider = NULL, subject_kind = NULL, top_k = integer(0), metric = character(0), table = NULL )DucksemanticsEmbeddingQuery( embedding = integer(0), provider = NULL, subject_kind = NULL, top_k = integer(0), metric = character(0), table = NULL )
embedding |
Numeric query embedding. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
top_k |
Number of nearest rows to return. |
metric |
One of |
table |
Optional table to search. Defaults to |
A DucksemanticsEmbeddingQuery object.
A judgment parser turns raw model text into a data frame that includes
mention_id and decision.
DucksemanticsJudgmentParserDucksemanticsJudgmentParser
A prompt runner accepts a prompt string and returns response text. BebeLM is one implementation; cloud LLMs, test fixtures, and other local models should implement the same generic instead of changing downstream judgment code.
DucksemanticsPromptRunnerDucksemanticsPromptRunner
S7 value object for a required non-empty character scalar.
DucksemanticsScalarText(value = character(0))DucksemanticsScalarText(value = character(0))
value |
Character scalar. |
A DucksemanticsScalarText object.
S7 value object for table and column identifiers used when constructing DuckDB SQL.
DucksemanticsSqlIdentifier(value = character(0), qualified = logical(0))DucksemanticsSqlIdentifier(value = character(0), qualified = logical(0))
value |
Identifier text. |
qualified |
Whether |
A DucksemanticsSqlIdentifier object.
S7 value object for a data frame with required columns.
value |
Data frame. |
required |
Required column names. |
allow_empty |
Whether zero-row input is allowed. |
A DucksemanticsTable object.
Token embedding batch for late-interaction storage
DucksemanticsTokenEmbeddingBatch( embeddings = integer(0), subject_id = character(0), subject_kind = character(0), provider = character(0), token_index = integer(0), block_id = character(0), token = NULL, start_offset = NULL, end_offset = NULL, attrs = NULL )DucksemanticsTokenEmbeddingBatch( embeddings = integer(0), subject_id = character(0), subject_kind = character(0), provider = character(0), token_index = integer(0), block_id = character(0), token = NULL, start_offset = NULL, end_offset = NULL, attrs = NULL )
embeddings |
Numeric matrix with one row per token. |
subject_id |
Subject identifier for each token row. |
subject_kind |
Subject type, e.g. |
provider |
Embedding provider label. |
token_index |
Token index within each subject block. Defaults to
zero-based order within |
block_id |
Matrix/block identifier. Defaults to one block per
|
token |
Optional token text for each row. |
start_offset, end_offset
|
Optional zero-based source offsets. |
attrs |
Optional JSON text or other metadata for each token row. |
Token vectors are always persisted as DuckDB FLOAT[] rows. This
makes the index durable and queryable without an external allocator.
A DucksemanticsTokenEmbeddingBatch object.
A token embedding provider accepts a character vector and returns one
token-embedding object per input text. Each object contains an embeddings
matrix and token metadata.
DucksemanticsTokenEmbeddingProviderDucksemanticsTokenEmbeddingProvider
Token embedding late-interaction query
DucksemanticsTokenEmbeddingQuery( embeddings = integer(0), provider = NULL, subject_kind = NULL, top_k = integer(0), table = NULL, candidate_subject_id = NULL )DucksemanticsTokenEmbeddingQuery( embeddings = integer(0), provider = NULL, subject_kind = NULL, top_k = integer(0), table = NULL, candidate_subject_id = NULL )
embeddings |
Numeric query-token matrix. |
provider |
Optional provider filter. |
subject_kind |
Optional subject-kind filter. |
top_k |
Number of scored blocks to return. |
table |
Optional table to search. Defaults to |
candidate_subject_id |
Optional candidate subject identifiers. |
A DucksemanticsTokenEmbeddingQuery object.