Overlap
UDTF: cugraph_overlap
Official cuGraph reference: C API
Compare explicit vertex pairs by dividing their shared-neighbor count by the smaller of their two neighbor counts.
Quickstart
The call below supplies edges from registered relation target_edges with canonical src and dst columns and may include weight, plus the registered relation candidate_pairs (the vertex_pairs relation with columns first, second). Substitute your own registered relations.
SELECT *
FROM cugraph_overlap(
edges => (SELECT src, dst FROM target_edges),
vertex_pairs => (SELECT first, second FROM candidate_pairs)
);
Inputs
Every relation is a named parenthesized SELECT subquery. The required edges role uses canonical src and dst columns; every role, its canonical columns, and their accepted Arrow types are listed under Relation arguments. Metadata validation resolves registered tables named in its JSON request.
Endpoint columns accept numeric Int32, Int64 vertex IDs or logical string Utf8, LargeUtf8, Utf8View vertex IDs; string vertex-identity outputs are canonicalized to Utf8 (native mapping Int64) while scores, distances, counts, coordinates, and opaque labels stay numeric. The shared vertex-ID contract is summarized in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.
Logical string side-input limitations:
- edge ID columns and edge-ID predicate side inputs are not supported for logical string graphs
- candidate-pair columns must match the graph vertex domain; logical string graphs accept Utf8, LargeUtf8, or Utf8View independently per column
Arguments and options
Relation arguments
Vertex columns of vertex_pairs must use the same vertex domain as edges: the integer type of src and dst, or any listed string type when the endpoints are strings. Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.
Named value arguments
This UDTF has no algorithm-specific value arguments. Its inputs are the relation arguments above and the graph construction options below.
Graph construction options
This UDTF requires directed=false (undirected/symmetric graph); all other graph construction options follow the shared defaults documented in Graph Construction Options.
Output
These are generic descriptor schemas; run gpu_validate_call to get the concrete, table-specific output schema.
Examples
This example runs on the citation network demo dataset.
Which broader reading lists cover the most of BERT's bibliography?
Compare the references of the 2018 BERT paper with NLP papers from 2015 through 2020. Candidates have at least 10 references, use one of the listed field labels, and have at least as many references as BERT. The smaller set is therefore BERT's 55-reference bibliography, and the overlap score is the share of that list also found in each candidate's bibliography.
The UDTF requires an undirected graph. Positive IDs represent citing papers and negative IDs represent cited papers in the reference role. This keeps papers that cite BERT on the positive-ID side and references on the negative-ID side. The edge projection omits weights, so each reference contributes one unit. Candidate pairs exclude title-identical BERT records.
CREATE OR REPLACE VIEW similarity_seed AS
SELECT paper_id, title, n_references
FROM papers
WHERE title = 'BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding'
AND year = 2018;
CREATE OR REPLACE VIEW similarity_candidates AS
SELECT p.paper_id, p.title, p.n_references, p.year
FROM papers p
WHERE p.year BETWEEN 2015 AND 2020
AND p.n_references >= 10
AND p.primary_fos IN (
'Natural language processing', 'Language model',
'Machine translation', 'Question answering');
CREATE OR REPLACE VIEW bibliography_edges AS
SELECT e.src, -e.dst AS dst
FROM citation_edges e
JOIN (
SELECT paper_id FROM similarity_seed
UNION
SELECT paper_id FROM similarity_candidates
) selected ON selected.paper_id = e.src;
SELECT p.year, p.title, p.n_references,
ROUND(r.similarity, 3) AS bert_reference_coverage
FROM cugraph_overlap(
edges => (SELECT src, dst FROM bibliography_edges),
vertex_pairs => (
SELECT s.paper_id AS first, c.paper_id AS second
FROM similarity_seed s
CROSS JOIN similarity_candidates c
WHERE LOWER(c.title) <> LOWER(s.title)
AND c.n_references >= s.n_references),
directed => false) r
JOIN papers p ON p.paper_id = r.second
ORDER BY r.similarity DESC, p.paper_id
LIMIT 5;
Linguistic Knowledge and Transferability of Contextual Representations covers 11 of BERT's 55 references, the largest share in this result at 0.2.
A score of 1 means that every reference in BERT's smaller list also appears in the candidate's list. Candidate citations to BERT and agreement with its claims are outside this measure. Compare with the Jaccard similarity example, which divides by the union of both lists.
Limits
- similarity is explicit-pair only; all-pairs candidate generation and all-pairs top-k search are not exposed
- vertex_pairs is a required relation with canonical first and second columns
- candidate-pair columns must match the graph vertex domain; logical string graphs accept Utf8, LargeUtf8, or Utf8View independently per column
- null candidate-pair values are rejected at execution and are never dropped
- candidate pairs are a multiset: duplicate, reversed, and self pairs remain distinct output rows
- result rows have no global ordering; use ORDER BY when order is required
- providing edges.weight selects weighted similarity; omitting it selects unit-weight similarity
- cuGraph requires directed=false so the graph is constructed as an undirected/symmetric view
To dry-run validate relation metadata, column types, and options without execution, see gpu_validate_call.