Skip to content

Graph Endpoints

13 endpoints under /v1/graph/ exposing Neo4j knowledge graph analytics for legal reasoning. All endpoints use POST and return results wrapped in { data, meta } envelopes.

All graph queries have a 15-second timeout. If Neo4j is unreachable, the API returns 503 SERVICE_UNAVAILABLE. Programming errors propagate as 500 INTERNAL_ERROR.

Detect active jurisprudential divergences — clusters of decisions with split outcomes (provido vs improvido) for the same legal criteria. The divergence_score is computed as minority / total, so a perfectly balanced 50/50 split scores highest.

ParameterTypeDefaultDescription
categoria_idstringnullFilter by legal category (e.g., cat-direito-consumidor). Omit for all categories.
limitinteger10Max divergence clusters returned (1-50)
Terminal window
curl -X POST http://localhost:8000/v1/graph/divergencias \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{ "categoria_id": "cat-direito-consumidor", "limit": 5 }'

Analyze how different ministers decide on the same legal topic. Returns per-minister outcome counts for criteria matching the topic.

ParameterTypeDefaultDescription
temastringrequiredLegal topic for divergence analysis (1-500 chars, e.g., dano moral)
Terminal window
curl -X POST http://localhost:8000/v1/graph/divergencias/turma \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{ "tema": "dano moral em relacoes de consumo" }'

Find arguments (criteria, legal statutes, precedents) with the highest success rate for a given legal category and desired outcome.

ParameterTypeDefaultDescription
categoria_idstringrequiredLegal category ID (e.g., cat-direito-consumidor)
resultado_desejadostring"provido"Target outcome: provido, improvido, or parcialmente provido
tipo_argumentostring"all"Filter by type: criterio, dispositivo, precedente, or all
min_decisionsinteger2Minimum supporting decisions for statistical relevance (2-100, internal floor is 2)
top_kinteger10Max arguments returned (1-50)
Terminal window
curl -X POST http://localhost:8000/v1/graph/optimal-argument \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"categoria_id": "cat-direito-consumidor",
"resultado_desejado": "provido",
"tipo_argumento": "criterio",
"min_decisions": 3
}'

POST /v1/graph/optimal-argument-by-ministro

Section titled “POST /v1/graph/optimal-argument-by-ministro”

Minister-specific variant of optimal argument. Compares a specific minister’s success rates against the overall category average. The delta field shows the difference: positive means the argument performs better with this minister.

ParameterTypeDefaultDescription
categoria_idstringrequiredLegal category ID
ministrostringrequiredMinister name (auto-normalized to uppercase)
resultado_desejadostring"provido"Target outcome
tipo_argumentostring"all"Argument type filter
min_decisionsinteger1Min minister-side decisions (1-100)
min_category_decisionsinteger2Min category-wide decisions (2-100, internal floor is 2)
top_kinteger10Max arguments returned (1-50)

The response includes recommended_arguments (delta > 0) and avoid_arguments (delta < -0.1).

Terminal window
curl -X POST http://localhost:8000/v1/graph/optimal-argument-by-ministro \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"categoria_id": "cat-direito-consumidor",
"ministro": "Nancy Andrighi",
"resultado_desejado": "provido"
}'

Comprehensive judicial behavior profile for a specific STJ minister: total decisions, date range, top criteria, outcome distribution, peer divergences, and most-cited decisions.

ParameterTypeDefaultDescription
ministrostringrequiredMinister name (auto-normalized to uppercase)
include_divergenciasbooleantrueInclude peer divergences on the same criteria
include_precedentesbooleantrueInclude most-cited decisions by this minister
limit_criteriosinteger10Max criteria in the ranking (1-50, store cap is 10)
Terminal window
curl -X POST http://localhost:8000/v1/graph/ministro-profile \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"ministro": "Nancy Andrighi",
"include_divergencias": true,
"include_precedentes": true,
"limit_criterios": 5
}'

Track how a legal criterion’s application changes over time. Returns per-period buckets with provido/improvido splits and a heuristic trend label (growing, declining, or stable).

ParameterTypeDefaultDescription
criteriostringrequiredLegal criterion to analyze (1-500 chars, e.g., dano moral)
granularitystring"year"Temporal granularity: year or month
periodo_iniciostringnullPeriod start. Format must match granularity: YYYY for year, YYYY-MM for month.
periodo_fimstringnullPeriod end. Same format requirement.
Terminal window
curl -X POST http://localhost:8000/v1/graph/temporal-evolution \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"criterio": "boa-fe objetiva",
"granularity": "year",
"periodo_inicio": "2018",
"periodo_fim": "2024"
}'

Trace the outbound citation chain from a root decision through CITA_PRECEDENTE relationships up to the specified depth.

ParameterTypeDefaultDescription
decisao_idstringrequiredRoot decision ID
max_depthinteger3Maximum citation hops (1-5)
Terminal window
curl -X POST http://localhost:8000/v1/graph/citation-chain \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{ "decisao_id": "doc-stj-resp-1234567", "max_depth": 3 }'

Rank the most influential decisions in the citation graph using a simplified PageRank score: in_citations * 10 + second_order * 3.

ParameterTypeDefaultDescription
limitinteger20Top-N most influential decisions (1-100)
min_citationsinteger0Minimum direct citations post-filter (0 = no filter)
Terminal window
curl -X POST http://localhost:8000/v1/graph/pagerank \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{ "limit": 10, "min_citations": 5 }'

Identify thematic communities of decisions that share legal criteria. Returns decision pairs grouped by shared criteria count (pairwise co-occurrence).

ParameterTypeDefaultDescription
min_sharedinteger3Minimum shared criteria to form a community pair (1-20)
limitinteger20Maximum communities returned (1-100)
Terminal window
curl -X POST http://localhost:8000/v1/graph/communities \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{ "min_shared": 4, "limit": 10 }'

Compare two decisions across five graph dimensions (criteria, facts, evidence, statutes, precedents) using weighted Jaccard scoring. Returns per-dimension similarity stats and a combined weighted_score in [0, 1].

ParameterTypeDefaultDescription
source_idstringrequiredFirst decision ID
target_idstringrequiredSecond decision ID
Terminal window
curl -X POST http://localhost:8000/v1/graph/structural-similarity \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_id": "doc-stj-resp-1234567",
"target_id": "doc-stj-resp-7654321"
}'

Find the shortest bidirectional path between two decisions in the knowledge graph, using all relationship types.

ParameterTypeDefaultDescription
source_idstringrequiredSource decision ID
target_idstringrequiredTarget decision ID
max_depthinteger10Maximum path depth in hops (1-20)

Returns nodes and edges with real relationship types, or found: false when no path exists within the depth limit.

Terminal window
curl -X POST http://localhost:8000/v1/graph/shortest-path \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_id": "doc-stj-resp-1234567",
"target_id": "doc-stj-resp-7654321",
"max_depth": 5
}'

Compute 7-dimensional structural feature vectors for decisions based on graph topology: criteria count, facts count, evidence count, statutes count, inbound citations, outbound citations, and encoded outcome.

ParameterTypeDefaultDescription
decisao_idsstring[]nullSpecific decision IDs. Omit for random sample mode. Max 500 IDs per request.
limitinteger100Sample size cap when decisao_ids is omitted (1-500)

Results are cached in Redis for 1 hour.

Terminal window
curl -X POST http://localhost:8000/v1/graph/embeddings \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"decisao_ids": ["doc-stj-resp-1234567", "doc-stj-resp-7654321"]
}'