Available Capture Groups for Indexing in Code-Graph-RAG: Complete Reference
Code-Graph-RAG provides ten predefined capture groups—such as io, call, inherit, and all—that map to specific RelationshipType values in codebase_rag.constants, allowing you to control exactly which edges and node labels are indexed via the CGR_CAPTURE environment variable or --capture CLI flag.
The vitali87/code-graph-rag library uses capture groups to determine which relationships and node labels are materialized when building a code knowledge graph. These symbolic names, defined in the CaptureGroup enum, offer a declarative mechanism to tune indexing granularity from lightweight data-flow tracking to exhaustive full-graph analysis.
What Are Capture Groups?
Capture groups are symbolic constants that resolve to sets of RelationshipType values (the graph edges) and their associated node labels. They are defined in codebase_rag/constants/core.py as members of the CaptureGroup enum and exposed through the CAPTURE_GROUP_RELS mapping, which associates each group name with a frozenset of relationship types.
When you supply a group name via the CGR_CAPTURE environment variable or the --capture CLI flag, the library invokes resolve_capture() in codebase_rag/capture.py to parse the input. This function uses split_spec() and _resolve_token() to look up groups, then builds a CaptureSelection object containing enabled_rels and enabled_node_labels. The graph-building components in codebase_rag/graph_loader.py and codebase_rag/graph_updater.py subsequently consult this selection to decide which edges to persist.
Complete List of Capture Groups for Indexing
The following capture groups are available in the main branch, each enabling a specific subset of relationships:
io— EnablesREADS_FROMandWRITES_TOrelationships to track data-flow edges between symbols.type— CapturesTYPE_OFandHAS_TYPEedges for type hierarchies and variable-to-type mappings.inherit— IndexesINHERITSandOVERRIDESrelationships to record class inheritance and method overrides.override— Focuses narrowly onOVERRIDESedges only, often used in conjunction with theinheritgroup.call— StoresCALLSandCALLED_BYedges to enable call-graph queries and dependency tracing.definition— TracksDEFINESandDEFINED_BYrelationships indicating where symbols are declared.import— MapsIMPORTSandIMPORTED_BYedges to monitor module-level dependencies.reference— Captures genericREFERENCESandREFERENCED_BYedges for variable usage and other citations.all— Includes every supportedRelationshipTypevalue, creating the most exhaustive index possible.none— Disables relationship indexing entirely, resulting in an empty relationship set (useful for debugging or custom pipelines).
How Capture Group Resolution Works
The resolution pipeline involves three key steps implemented in codebase_rag/capture.py:
- Tokenization — The
split_spec()function parses comma-separated strings (e.g.,"io,call,-definition") into individual tokens. - Resolution —
_resolve_token()looks up each token againstCAPTURE_GROUP_RELSincodebase_rag/constants/core.py, handling negative prefixes (e.g.,-call) to exclude relationships. - Assembly —
resolve_capture()constructs aCaptureSelectioninstance combining all enabled relationships and deriving the necessaryenabled_node_labelsfromCAPTURE_GROUP_NODE_LABELS.
During indexing, graph_loader.py and graph_updater.py filter the AST analysis results through selection.enabled_rels, ensuring only the specified edges are written to the graph store.
Practical Configuration Examples
You can configure capture groups programmatically or through environment variables.
Example 1: Using Environment Variables
from codebase_rag.capture import default_capture
# Assumes CGR_CAPTURE environment variable is set to "io,inherit"
selection = default_capture()
print(selection.enabled_rels)
# Output: {READS_FROM, WRITES_TO, INHERITS, OVERRIDES}
print(selection.enabled_node_labels)
# Output: set of node labels required for those edges
Example 2: Parsing CLI Flags
from codebase_rag.capture import resolve_capture, split_spec
# Simulating input: cgr --capture io,call,definition
tokens = split_spec("io,call,definition")
selection = resolve_capture(tokens)
print(selection.enabled_rels)
# Output: {READS_FROM, WRITES_TO, CALLS, CALLED_BY, DEFINES, DEFINED_BY}
Example 3: Excluding Specific Groups
from codebase_rag.capture import resolve_capture, split_spec
# Simulating input: cgr --capture all,-call
tokens = split_spec("all,-call")
selection = resolve_capture(tokens)
# Result includes all relationships except CALLS and CALLED_BY
print(selection.enabled_rels)
Summary
- The
CaptureGroupenum incodebase_rag/constants/core.pydefines ten symbolic groups ranging fromiotoall. CAPTURE_GROUP_RELSmaps each group to afrozensetofRelationshipTypeobjects, whileCAPTURE_GROUP_NODE_LABELStracks the associated node types.- Use
resolve_capture()incodebase_rag/capture.pyto convert--captureCLI flags orCGR_CAPTUREenvironment values into aCaptureSelection. - The
enabled_relsandenabled_node_labelsattributes ofCaptureSelectiondrive indexing decisions incodebase_rag/graph_loader.pyandcodebase_rag/graph_updater.py. - Exclude unwanted groups using the
-prefix (e.g.,all,-call) to fine-tune the index scope.
Frequently Asked Questions
What is the difference between the inherit and override capture groups?
The inherit group indexes both INHERITS and OVERRIDES relationship types, capturing complete class hierarchies and inheritance chains. The override group is more selective, indexing only OVERRIDES edges to focus specifically on method overriding behavior without the broader inheritance structure.
How do I index all relationship types in Code-Graph-RAG?
Use the all capture group, which expands to include every RelationshipType value defined in the system. Set the environment variable CGR_CAPTURE=all or pass --capture all via the CLI to enable comprehensive indexing of all supported edges.
Can I combine multiple capture groups or exclude specific ones?
Yes. The split_spec() function in codebase_rag/capture.py supports comma-separated combinations and negative prefixes. You can specify io,call to merge groups, or all,-call to include everything while omitting call relationships. The resolve_capture() function processes these tokens into a unified CaptureSelection with the effective set of enabled_rels.
Where are capture group constants defined in the codebase?
The CaptureGroup enum and the CAPTURE_GROUP_RELS mapping are declared in codebase_rag/constants/core.py and re-exported through codebase_rag/constants/__init__.py. The resolution logic resides in codebase_rag/capture.py, while the consuming components are located in codebase_rag/graph_loader.py and codebase_rag/graph_updater.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →