| Title: | DuckDB-Native Semantic and Retrieval Relations |
|---|---|
| Description: | DuckDB-native ontology graphs, validated Human Phenotype Ontology (HPO) observations, typed release-cataloged Monarch relations including read-only projections of attached dated packs, provider/snapshot-catalog-bound literature retrieval, and source-grounded semantic judgments. Bulk values are ordinary relations; optional S7 protocols are reserved for real prompt, embedding, parser, and annotator providers. The package does not store ClinVar or PubMed source data, download Monarch packs, rank cases, or evaluate benchmarks. |
| 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.2.1 |
| Built: | 2026-10-04 09:56:14 UTC |
| Source: | https://github.com/RGenomicsETL/ducksemantics |
These candidates are not accepted observations. Use
ducksemantics_hpo_observations() to validate a separately accepted HPO
observation relation against source documents.
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 |
Source text. |
document_id |
Optional source-document identity. |
prefix |
Table prefix. |
longest_match |
Drop spans contained by a longer span. |
record |
Append candidate rows to the semantic mention table. |
Candidate data frame.
Create a BebeLM prompt provider
ducksemantics_bebel_runner(agent, on_event = NULL)ducksemantics_bebel_runner(agent, on_event = NULL)
agent |
An |
on_event |
Optional 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 |
Accepted tool-call names, or |
An object implementing DucksemanticsJudgmentParser.
Materialize transitive closure SQL
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 |
Non-empty predicate names, or |
source_table |
Source edge relation. |
target_table |
Target closure relation. |
SQL script.
Create a native ColBERT provider
ducksemantics_colbert_provider( model, role = c("document", "query"), label = "Rbebelm ColBERT" )ducksemantics_colbert_provider( model, role = c("document", "query"), label = "Rbebelm ColBERT" )
model |
An |
role |
Query or document encoding role. |
label |
Provider identity. |
An object implementing DucksemanticsTokenEmbeddingProvider.
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 path or |
read_only |
Open read-only. |
array |
DuckDB array conversion mode. |
A DBI connection.
Default source-grounded judgment instructions
ducksemantics_default_judgment_instructions()ducksemantics_default_judgment_instructions()
A character scalar.
Bulk embedding values are an ordinary data frame with one FLOAT[]-ready
numeric vector per row; they are not an S7 value object.
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 |
Finite numeric matrix with one row per subject. |
subject_id |
Non-empty subject identifiers. |
subject_kind |
Subject type. |
provider |
Provider identity. |
text |
Optional source text per row. |
attrs |
Optional metadata text per row. |
A data frame suitable for ducksemantics_write_embeddings().
Wrap an embedding function as an embedding provider
ducksemantics_embedding_provider(fun, label = "function")ducksemantics_embedding_provider(fun, label = "function")
fun |
Function accepting a prompt and returning response text. |
label |
Provider identity. |
An object implementing DucksemanticsEmbeddingProvider.
Search dense embeddings
ducksemantics_embedding_search( conn, embedding, provider = NULL, subject_kind = NULL, top_k = 10L, metric = c("cosine", "cosine_distance", "l2", "inner_product"), table = NULL )ducksemantics_embedding_search( conn, embedding, provider = NULL, subject_kind = NULL, top_k = 10L, metric = c("cosine", "cosine_distance", "l2", "inner_product"), table = NULL )
conn |
DBI connection. |
embedding |
Numeric query vector. |
provider |
Optional provider identity. |
subject_kind |
Optional subject-kind filter. |
top_k |
Number of results. |
metric |
|
table |
Caller-selected embedding table. |
Ranked embedding rows.
Create an EmbeddingGemma 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 |
An |
label |
Provider identity. |
task |
EmbeddingGemma task. |
title |
Optional document title. |
dimensions |
Matryoshka dimension. |
normalize |
L2-normalize output rows. |
truncate |
Truncate overly long input. |
check_interrupt |
Poll for R interrupts. |
An object implementing DucksemanticsEmbeddingProvider.
The final observation relation has exactly these required semantic fields:
document_id, hpo_id, start_offset, end_offset, source_text,
context_status, method, provider_id, provider_version,
confidence, and status. Offsets are zero-based, half-open R character
offsets. Lexical candidates returned by ducksemantics_annotate() are not
observations and cannot be substituted for this relation.
ducksemantics_hpo_observation_contract()ducksemantics_hpo_observation_contract()
Required HPO observation column names.
Validate accepted HPO observations against source documents
ducksemantics_hpo_observations(documents, observations, conn = NULL)ducksemantics_hpo_observations(documents, observations, conn = NULL)
documents |
Data frame (or a caller-owned DuckDB table name with
|
observations |
Data frame (or caller-owned DuckDB table name) following
|
conn |
Optional DBI connection for a lazy caller-owned table name. |
Validated accepted-observation data frame.
Build the lexical alias index
ducksemantics_index_aliases(conn, prefix = "semantic")ducksemantics_index_aliases(conn, prefix = "semantic")
conn |
DBI connection. |
prefix |
Table prefix. |
Invisibly, index table name.
Initialize semantic graph tables
ducksemantics_init(conn, prefix = "semantic")ducksemantics_init(conn, prefix = "semantic")
conn |
DBI connection. |
prefix |
Table prefix. |
Invisibly, conn.
Create a JSON judgment parser
ducksemantics_json_judgment_parser()ducksemantics_json_judgment_parser()
An object implementing DucksemanticsJudgmentParser.
Judge lexical candidates with a provider
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 |
Candidate relation. |
runner |
Prompt provider. |
conn |
Optional DBI connection to record judgments. |
prefix |
Table prefix. |
graph_context |
Optional graph context. |
instructions |
Explicit judgment instructions. |
prompt_builder |
Function building the prompt. |
parser |
Judgment parser provider. |
record |
Record result when |
model |
Provider/model identity. |
... |
Arguments passed to |
Source-grounded judgment relation.
Build a source-grounded 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 |
Candidate data frame. |
graph_context |
Optional graph context relation. |
instructions |
Explicit judgment policy. |
Prompt text.
Exact token-level late-interaction search
ducksemantics_late_interaction_search( conn, embeddings, provider = NULL, subject_kind = NULL, top_k = 10L, table = NULL, candidate_subject_id = NULL )ducksemantics_late_interaction_search( conn, embeddings, provider = NULL, subject_kind = NULL, top_k = 10L, table = NULL, candidate_subject_id = NULL )
conn |
DBI connection. |
embeddings |
Numeric query-token matrix. |
provider |
Optional provider identity. |
subject_kind |
Optional subject-kind filter. |
top_k |
Number of blocks to return. |
table |
Caller-selected token embedding table. |
candidate_subject_id |
Optional candidate restriction. |
Ranked exact MaxSim rows.
Create the default lexical grounding provider
ducksemantics_lexical_annotator()ducksemantics_lexical_annotator()
An object implementing DucksemanticsAnnotator.
RClinVarbitration owns the article and section relations. Retrieval binds a
provider and exact cataloged source-order cutoff, selects the maximum article
source_ordinal at or below that cutoff per provider/article, drops a latest
deletion event, and joins only sections from that exact version. It never
imports, writes, or fetches literature.
ducksemantics_literature_retrieve( articles, sections, snapshots, query, provider_id, snapshot_id, section_names = NULL, conn = NULL )ducksemantics_literature_retrieve( articles, sections, snapshots, query, provider_id, snapshot_id, section_names = NULL, conn = NULL )
articles |
Caller-owned relation with |
sections |
Caller-owned relation with |
snapshots |
Source snapshot catalog from
|
query |
Non-empty lexical query text. |
provider_id |
Provider identity. |
snapshot_id |
Exact provider snapshot identity. |
section_names |
Optional non-empty section names to search; |
conn |
Optional DBI connection for table relations. |
A read-only RClinVarbitration projection joins pubmed_sources to
pubmed_articles and pubmed_abstracts: use source provider as
provider_id, source id as version_id/snapshot_id, source ordinal for
both ordinal fields, and source_applied_at as effective_at. A section
must retain the exact article event's version id and source ordinal.
Exact non-empty source spans from non-deleted article versions visible at the cataloged source-order cutoff.
RClinVarbitration owns article and section storage. This catalog identifies
a provider snapshot by its source-order cutoff; it creates no shadow
literature table.
ducksemantics_literature_snapshot_catalog(snapshots, conn = NULL)ducksemantics_literature_snapshot_catalog(snapshots, conn = NULL)
snapshots |
Data frame or caller-owned DuckDB table name containing
|
conn |
Optional DBI connection for a table relation. |
Validated source snapshot catalog.
Materialize a fixed-dimension embedding table
ducksemantics_materialize_embedding_index( conn, dimensions, provider = NULL, subject_kind = NULL, table = NULL, source_table = "semantic_embeddings", hnsw = FALSE, metric = "cosine" )ducksemantics_materialize_embedding_index( conn, dimensions, provider = NULL, subject_kind = NULL, table = NULL, source_table = "semantic_embeddings", hnsw = FALSE, metric = "cosine" )
conn |
DBI connection. |
dimensions |
Embedding width. |
provider |
Optional provider filter. |
subject_kind |
Optional subject kind filter. |
table |
Target table name. |
source_table |
Source embedding table. |
hnsw |
Create an optional DuckDB HNSW index. |
metric |
HNSW metric. |
Target table name.
The selected training and holdout releases must be exact rows of one typed provider catalog. The result is a provenance-preserving anti-join.
ducksemantics_monarch_gene_disease_holdout_audit( facts, releases, provider_id, train_release_id, holdout_release_id, conn = NULL )ducksemantics_monarch_gene_disease_holdout_audit( facts, releases, provider_id, train_release_id, holdout_release_id, conn = NULL )
facts |
Caller-supplied gene-disease relation. |
releases |
Typed Monarch release catalog. |
provider_id |
Provider identity. |
train_release_id |
Exact training release identity. |
holdout_release_id |
Exact holdout release identity. |
conn |
Optional DBI connection for table relations. |
Holdout rows absent from the historical relation.
This function never downloads Monarch data. A typed release catalog is required to prove that every fact has a known provider/release identity.
ducksemantics_monarch_import( facts, releases, relation = c("gene_phenotype", "gene_disease", "disease_phenotype"), conn = NULL, table = NULL, replace = FALSE )ducksemantics_monarch_import( facts, releases, relation = c("gene_phenotype", "gene_disease", "disease_phenotype"), conn = NULL, table = NULL, replace = FALSE )
facts |
Gene-phenotype, gene-disease, or disease-phenotype data frame,
or a caller-owned DuckDB table name with |
releases |
Typed catalog from |
relation |
One of |
conn |
Optional DBI connection. |
table |
Optional destination table when |
replace |
Replace destination rows. |
Normalized Monarch relation.
Projects an already attached read-only official Monarch DuckDB pack into
connection-local temporary views. It never attaches, downloads, collects,
copies, rewrites, or merges pack rows. source_catalog must name an attached
DuckDB catalog whose main
schema contains the official denormalized_edges, nodes,
information_content, and node_has_phenotype tables. The edge table is
checked before any view is made, including its scalar role categories,
provider-serialized text negation, and array provenance fields. The official
required nodes, node_has_phenotype, and information_content projection
columns/types are also validated.
ducksemantics_monarch_project_pack( conn, source_catalog, releases, provider_id, release_id, prefix = "semantic_monarch" )ducksemantics_monarch_project_pack( conn, source_catalog, releases, provider_id, release_id, prefix = "semantic_monarch" )
conn |
Valid DBI connection with the pack already attached. |
source_catalog |
Attached DuckDB catalog name, not the current catalog. |
releases |
Typed Monarch release catalog or caller-owned catalog table. This binds provider/release semantics; the caller must verify the immutable file receipt before attaching the pack. |
provider_id |
Exact provider identity in |
release_id |
Exact, dated release identity in |
prefix |
Safe unqualified prefix for temporary view names. |
associations retains every source edge and all source columns exactly, then
adds the selected provider and release. Each role view is likewise a total
projection: it retains raw source columns and adds normalized role columns,
source_subject, source_object, source_direction, and
association_status. Only supported_subject_to_object and
supported_object_to_subject rows have non-missing normalized roles.
missing_endpoint, missing_predicate, malformed_negation,
missing_role_category, malformed_role_category, negated, and
unsupported_orientation are not support. negation_status separately
distinguishes not_provided, not_negated, negated, and malformed:
Monarch omits the optional qualifier on many positive assertion rows, so
omission is retained but does not erase the assertion. In particular, a
missing predicate never becomes a causal predicate.
A data frame naming the seven connection-local temporary views, with
relation, view_name, provider_id, and release_id columns. It does
not return pack contents.
Select one cataloged Monarch release
ducksemantics_monarch_query( facts, releases, relation = c("gene_phenotype", "gene_disease", "disease_phenotype"), provider_id, release_id = NULL, as_of = NULL, as_of_ordinal = NULL, conn = NULL )ducksemantics_monarch_query( facts, releases, relation = c("gene_phenotype", "gene_disease", "disease_phenotype"), provider_id, release_id = NULL, as_of = NULL, as_of_ordinal = NULL, conn = NULL )
facts |
Monarch fact relation or a caller-owned DuckDB table name. |
releases |
Typed Monarch release catalog. |
relation |
Relation type. |
provider_id |
Provider identity to bind. |
release_id |
Exact catalog release identity. |
as_of |
Typed |
as_of_ordinal |
Numeric source-order cutoff. |
conn |
Optional DBI connection for table relations. |
Facts from one selected provider/release. Selection metadata is held
in release_selected and provider_selected attributes.
A catalog row identifies one provider release. It must carry either a typed
effective_date (Date or POSIXct) or a finite numeric
source_ordinal; both may be supplied when the provider declares both.
ducksemantics_monarch_release_catalog(releases, conn = NULL)ducksemantics_monarch_release_catalog(releases, conn = NULL)
releases |
Data frame or caller-owned DuckDB table name containing
|
conn |
Optional DBI connection for a table relation. |
Validated release catalog.
Normalize semantic text
ducksemantics_normalize(text)ducksemantics_normalize(text)
text |
Character vector. |
Normalized character vector.
Project edge-shaped data to graph SQL
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 relation name. |
from, predicate, to
|
Source columns. |
target_table |
Target table. |
attrs, trust
|
Optional source columns. |
SQL script.
Wrap a prompt function as a prompt provider
ducksemantics_prompt_runner(fun, label = "function")ducksemantics_prompt_runner(fun, label = "function")
fun |
Function accepting a prompt and returning response text. |
label |
Provider identity. |
An object implementing DucksemanticsPromptRunner.
These S7 generics are reserved for real pluggable providers. All bulk input and output remains an ordinary data frame or matrix.
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 response text. |
annotator |
Grounding provider. |
conn |
DBI connection. |
document_id |
Optional document identifier. |
prefix |
Semantic-table prefix. |
longest_match |
Drop nested lexical candidates. |
record |
Persist candidates. |
Provider-specific text, matrix, or data frame.
Read an OBO ontology into graph relations
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 |
Ontology family. |
source |
Alias source identity. |
include_obsolete |
Include obsolete terms. |
A list of nodes, aliases, and edges data frames.
Record source-grounded judgments
ducksemantics_record_judgments(conn, judgments, prefix = "semantic")ducksemantics_record_judgments(conn, judgments, prefix = "semantic")
conn |
DBI connection. |
judgments |
Judgment relation. |
prefix |
Table prefix. |
Invisibly, validated judgment rows.
DuckDB semantic graph schema
ducksemantics_schema_sql(prefix = "semantic")ducksemantics_schema_sql(prefix = "semantic")
prefix |
Prefix for semantic tables. |
Character DDL statements.
Semantic table names
ducksemantics_tables(prefix = "semantic")ducksemantics_tables(prefix = "semantic")
prefix |
Table prefix. |
A named character vector.
Construct token embedding rows
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 |
Finite numeric matrix with one row per subject. |
subject_id |
Non-empty subject identifiers. |
subject_kind |
Subject type. |
provider |
Provider identity. |
token_index |
Zero-based token index within a document block. |
block_id |
Optional block identifier. |
token |
Optional token text. |
start_offset, end_offset
|
Optional zero-based half-open source offsets. |
attrs |
Optional metadata text per row. |
A data frame suitable for ducksemantics_write_token_embeddings().
Construct token embedding rows 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 DucksemanticsTokenEmbeddingProvider. |
subject_id |
Subject identifiers for input texts. |
subject_kind |
Subject type for stored rows. |
provider_label |
Stored provider identity. |
block_id |
Optional block identifier per input text. |
attrs |
Optional metadata per input text. |
... |
Arguments forwarded to |
A token-embedding data frame.
Wrap a token embedding function as a token provider
ducksemantics_token_embedding_provider(fun, label = "function-token")ducksemantics_token_embedding_provider(fun, label = "function-token")
fun |
Function accepting a prompt and returning response text. |
label |
Provider identity. |
An object implementing DucksemanticsTokenEmbeddingProvider.
Tokenize source text
ducksemantics_tokens(text)ducksemantics_tokens(text)
text |
Character scalar. |
Token data frame with zero-based half-open character offsets.
Store embedding rows in DuckDB
ducksemantics_write_embeddings( conn, embeddings, prefix = "semantic", replace = FALSE )ducksemantics_write_embeddings( conn, embeddings, prefix = "semantic", replace = FALSE )
conn |
DBI connection. |
embeddings |
Data frame from |
prefix |
Table prefix. |
replace |
Replace existing rows with the same subject and provider. |
Invisibly, written rows.
Write ontology graph rows
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 |
Table prefix. |
replace |
Replace supplied target relations. |
index |
Rebuild lexical alias index. |
Invisibly, semantic table names.
Write an OBO ontology into the graph
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 |
Ontology family. |
source |
Alias source identity. |
prefix |
Table prefix. |
replace |
Replace graph data. |
index |
Rebuild alias index. |
include_obsolete |
Include obsolete terms. |
Parsed graph relations, invisibly.
Store token embedding rows in DuckDB
ducksemantics_write_token_embeddings( conn, embeddings, prefix = "semantic", replace = FALSE )ducksemantics_write_token_embeddings( conn, embeddings, prefix = "semantic", replace = FALSE )
conn |
DBI connection. |
embeddings |
Data frame from |
prefix |
Table prefix. |
replace |
Replace existing rows with the same subject and provider. |
Invisibly, written rows.
Grounding-provider protocol
DucksemanticsAnnotatorDucksemanticsAnnotator
Embedding-provider protocol
DucksemanticsEmbeddingProviderDucksemanticsEmbeddingProvider
Judgment-parser provider protocol
DucksemanticsJudgmentParserDucksemanticsJudgmentParser
Prompt-runner provider protocol
DucksemanticsPromptRunnerDucksemanticsPromptRunner
Token-embedding-provider protocol
DucksemanticsTokenEmbeddingProviderDucksemanticsTokenEmbeddingProvider