Static analysis and RAG-optimized chunking for Business Central AL files
Project description
bc-al-chunker
RAG-optimized chunking for Business Central AL files.
bc-al-chunker statically parses .al files and produces semantically-aware chunks optimized for embedding and retrieval-augmented generation (RAG). It understands the structure of every AL object type — tables, pages, codeunits, reports, queries, enums, interfaces, and all extension types — and splits large objects at natural semantic boundaries (sections, procedures, triggers) while keeping small objects whole.
Features
- Hierarchical chunking — small objects stay whole; large objects split at procedure/trigger/section boundaries
- Context headers — every sub-chunk gets a synthetic context comment so each chunk is self-contained for embedding
- All AL object types — table, page, codeunit, report, query, xmlport, enum, interface, permissionset, profile, controladdin, entitlement, and all extension variants
- Multiple data sources — local filesystem, GitHub API, Azure DevOps API
- Structured output — Python dataclasses with JSON and JSONL export
- Zero dependencies for core usage —
httpxonly needed for remote adapters - Fully typed — strict mypy, PEP 561
py.typedmarker
Installation
# Core (local filesystem only)
pip install bc-al-chunker
# With GitHub adapter
pip install bc-al-chunker[github]
# With Azure DevOps adapter
pip install bc-al-chunker[azure]
# Everything
pip install bc-al-chunker[all]
Quick Start
from bc_al_chunker import chunk
# Chunk all .al files in a directory
chunks = chunk("/path/to/al-repo")
# Multiple repositories
chunks = chunk(["/repo1", "/repo2"])
# Each chunk has content + rich metadata
for c in chunks:
print(c.metadata.object_type, c.metadata.object_name, c.metadata.chunk_type)
print(c.content[:100])
print(c.token_estimate)
Configuration
from bc_al_chunker import chunk, ChunkingConfig
chunks = chunk(
"/path/to/repo",
config=ChunkingConfig(
max_chunk_chars=2000, # Max characters per chunk (default: 1500)
min_chunk_chars=100, # Min characters per chunk (default: 100)
include_context_header=True, # Prepend object context to sub-chunks
estimate_tokens=True, # Include token estimate on each chunk
),
)
Remote Sources
from bc_al_chunker import chunk_source
from bc_al_chunker.adapters.github import GitHubAdapter
from bc_al_chunker.adapters.azure_devops import AzureDevOpsAdapter
# GitHub
chunks = chunk_source(
GitHubAdapter("microsoft/BCApps", token="ghp_...", paths=["src/"])
)
# Azure DevOps
chunks = chunk_source(
AzureDevOpsAdapter("myorg", "myproject", "myrepo", token="pat...")
)
Export
from bc_al_chunker import chunk, chunks_to_json, chunks_to_jsonl, chunks_to_dicts
chunks = chunk("/path/to/repo")
# JSON array
chunks_to_json(chunks, "output.json")
# JSONL (streaming-friendly)
chunks_to_jsonl(chunks, "output.jsonl")
# Python dicts (for programmatic use)
dicts = chunks_to_dicts(chunks)
Chunking Strategy
The chunker uses a hierarchical, AST-aware strategy:
- Parse — Each
.alfile is parsed into anALObjectAST with sections, procedures, triggers, and properties identified - Size check — If the object's source is ≤
max_chunk_chars, it becomes oneWholeObjectchunk - Split — Large objects are split:
- Header chunk — object declaration + top-level properties
- Section chunks —
fields,keys,layout,actions,views,dataset, etc. - Procedure/Trigger chunks — each procedure or trigger as its own chunk
- Context injection — Sub-chunks get a context header prepended:
// Object: codeunit 50100 "Address Management" // File: src/Codeunits/AddressManagement.al procedure ValidateAddress(var CustAddr: Record "Customer Address") begin ... end;
This ensures every chunk is self-contained and produces high-quality embeddings for code search.
Chunk Schema
Each Chunk contains:
content— the text to embedtoken_estimate— approximate token count (chars / 4)metadata:file_path,object_type,object_id,object_namechunk_type—whole_object,header,section,procedure,triggersection_name,procedure_nameextends— for extension objectssource_table— extracted from page/codeunit propertiesattributes— e.g.,[EventSubscriber(...)]line_start,line_end
Development
# Clone and install
git clone https://github.com/andrijantasevski/bc-al-chunker.git
cd bc-al-chunker
uv sync --all-extras --group dev
# Run tests
uv run pytest tests/ -v
# Lint + format
uv run ruff check src/ tests/
uv run ruff format src/ tests/
# Type check
uv run mypy src/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bc_al_chunker-0.1.0.tar.gz.
File metadata
- Download URL: bc_al_chunker-0.1.0.tar.gz
- Upload date:
- Size: 34.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
252fa3a852cca5e4bd639cb23545c815136e49ea7a9f050623afbc312e9584fa
|
|
| MD5 |
89f752c3543c251b4445991bdeaf45a4
|
|
| BLAKE2b-256 |
0374211004ed456f202b358d102c72b908f4b61c938df1368318f7b77839378b
|
File details
Details for the file bc_al_chunker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bc_al_chunker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baf603e16fee0d1a2778cb88ec2442146fed9279f05a421060f51c315cf629d4
|
|
| MD5 |
1d45de9e5ac1ea40af099cd7707b1dea
|
|
| BLAKE2b-256 |
c8c795fbdbcc2805f437c6d6ca724228d85c3b562fc7bfeaed6324e1401496f2
|