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 — Enables READS_FROM and WRITES_TO relationships to track data-flow edges between symbols.
  • type — Captures TYPE_OF and HAS_TYPE edges for type hierarchies and variable-to-type mappings.
  • inherit — Indexes INHERITS and OVERRIDES relationships to record class inheritance and method overrides.
  • override — Focuses narrowly on OVERRIDES edges only, often used in conjunction with the inherit group.
  • call — Stores CALLS and CALLED_BY edges to enable call-graph queries and dependency tracing.
  • definition — Tracks DEFINES and DEFINED_BY relationships indicating where symbols are declared.
  • import — Maps IMPORTS and IMPORTED_BY edges to monitor module-level dependencies.
  • reference — Captures generic REFERENCES and REFERENCED_BY edges for variable usage and other citations.
  • all — Includes every supported RelationshipType value, 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:

  1. Tokenization — The split_spec() function parses comma-separated strings (e.g., "io,call,-definition") into individual tokens.
  2. Resolution — _resolve_token() looks up each token against CAPTURE_GROUP_RELS in codebase_rag/constants/core.py, handling negative prefixes (e.g., -call) to exclude relationships.
  3. Assembly — resolve_capture() constructs a CaptureSelection instance combining all enabled relationships and deriving the necessary enabled_node_labels from CAPTURE_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 CaptureGroup enum in codebase_rag/constants/core.py defines ten symbolic groups ranging from io to all.
  • CAPTURE_GROUP_RELS maps each group to a frozenset of RelationshipType objects, while CAPTURE_GROUP_NODE_LABELS tracks the associated node types.
  • Use resolve_capture() in codebase_rag/capture.py to convert --capture CLI flags or CGR_CAPTURE environment values into a CaptureSelection.
  • The enabled_rels and enabled_node_labels attributes of CaptureSelection drive indexing decisions in codebase_rag/graph_loader.py and codebase_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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →