CQLizer is a CQL (Corpus Query Language) parser, attribute validator and data-driven evaluator of query complexity.
It can serve in the following modes:
- HTTP API server
- MCP Server
- REPL (mostly for testing and debugging)
- CQL query parsing and AST generation using PEG grammar
- Machine learning-based query performance prediction (Random Forest, Neural Network, XGBoost)
- Data import from KonText log files
- Multiple interfaces: CLI, REPL, and API server
- Go 1.24+
- pigeon parser generator (for development)
# Install dependencies
make tools
# Build the binary
make build# Show version information
cqlizer version
# Start interactive REPL
cqlizer repl <model_file.json>
# Extract features from query logs
cqlizer featurize config.json logfile.jsonl output.msgpack
# Train a model
cqlizer learn [options] config.json features_file.msgpack
# Start API server
cqlizer server config.json
# Start MCP server (experimental)
cqlizer mcp-server config.json# Random Forest
cqlizer learn -model rf -num-trees 100 config.json features.msgpack
# Neural Network
cqlizer learn -model nn config.json features.msgpackFor XGBoost, the learn action extracts features into a format compatible with LightGBM. After running the extraction, use the Python script to train the model.
First, set up a Python virtual environment with the required dependencies:
python3 -m venv venv
source venv/bin/activate
pip install lightgbm==3.3.5 msgpack numpy scikit-learnThen run the training:
# Step 1: Extract features
cqlizer learn -model xg config.json features.msgpack
# Step 2: Train the model using Python
python scripts/learnxgb.py --input ./cql_features.v3.17.msgpack --output ./cql_model.v3.17.model.xg.txtUse cqlizer help <command> for detailed information about specific commands.
Most actions need a proper JSON configuration file. You can use the sample configuration file conf-sample.json as a base.
Note: conf-sample.json is configured with testing XGBoost model files located in the testdata/ directory.
The mcp-server action is configured entirely via environment variables (rather than
command-line flags):
LOG_PATH- Path to the log file. If unset, defaults to$XDG_STATE_HOME/cqlizer/cqlizer.log(or~/.local/state/cqlizer/cqlizer.logifXDG_STATE_HOMEis not set). Set tostderrto log to stderr instead of a file.LOG_LEVEL- Logging verbosity:debug,info,warning/warn, orerror. Defaults toinfo.REGISTRY_PATH- Path to the Manatee corpora registry directory, used to look up corpus structure (positional attributes, structures, structural attributes) for thecql_validateandget_corpus_structuretools. Defaults to/var/opt/manatee/registry.MODE- Transport mode for the MCP server:stdioorhttp. Defaults tostdio.LISTEN_ADDRESS- Address the server listens on whenMODE=http(e.g.localhost:8080). Ignored instdiomode. Defaults tolocalhost:8080.CQLIZER_CONF_PATH- Path to the JSON configuration file (same format as used by the othercqlizeractions, seeconf-sample.json). It provides the RF/XGBoost model ensemble (enables thecql_eval_complexitytool) and per-corpus properties such as size and language. This is effectively required - without it, model-based query evaluation is unavailable.CORPUS_STRUCTURE_TOOL_ENABLED- Set to1to expose theget_corpus_structuretool, which lets clients list all positional attributes and structures of a corpus. Disabled by default.DQD_TOOLS_ENABLED- Set to1to expose tools working with CQL for LCP (LiRI Corpus Platform) corpora translated to DQD. The other tools know Manatee corpora (REGISTRY_PATH) only. Instead of looking the corpus up, the DQD tools take its layer info (JSON) in thelayer_infoargument, so the caller decides which corpora exist and which version of their layer info applies (corpus_idis just a label in the output). They are meant for applications (e.g. NLQL) rather than for models directly:dqd_corpus_structure(corpus_id, layer_info)- the corpus in terms of CQL as translated to DQD (attributes, structures, values of categorical attributes)dqd_validate_cql(corpus_id, q, layer_info)- checks a CQL query can be translated to DQD and plain values of categorical attributes are validdqd_translate_cql(corpus_id, q, layer_info)- translates a CQL query to DQD
Important: The model is trained on data from a specific server which has its own load and performance characteristics. For proper deployment in production, it is necessary to train the model on data obtained from your own server to ensure accurate performance predictions.
The most affected feature is corpus size, as e.g. on a less powerful machine than the one we used to train the sample model, there will likely be too many false negatives (and vice versa - a more powerful server will cause more false positives).
# Generate parser from PEG grammar
make generate
# Run tests
go test ./...
# Build everything
make all