# queelius/elasticsearch-lm architecture

> Architecture diagram of the GitHub repository queelius/elasticsearch-lm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/queelius/elasticsearch-lm
- Repository: https://github.com/queelius/elasticsearch-lm

## Overview

This repository is a small toolkit for preparing Elasticsearch NLQ-to-Query-DSL examples and expanding them with an Ollama-hosted model. The main workflow samples seed examples, builds a prompt, requests synthetic JSON, and prints the parsed response. Separate utilities extract JSON from text, validate and transform datasets, and merge or summarize them. The README also describes fine-tuning and inference goals, but no training or inference implementation appears in the supplied tree; those capabilities are therefore represented only as documented context, not as runtime components.

Main entry points: [`generate_synthetic_data.py`](https://github.com/queelius/elasticsearch-lm/blob/main/generate_synthetic_data.py) (Synthetic generator), [`data_tool.py`](https://github.com/queelius/elasticsearch-lm/blob/main/data_tool.py) (Dataset reader and validator), [`extract_json_mapping.py`](https://github.com/queelius/elasticsearch-lm/blob/main/extract_json_mapping.py) (Mapping extractor), [`generate_prompt.py`](https://github.com/queelius/elasticsearch-lm/blob/main/generate_prompt.py) (Prompt builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Synthetic generation"]
  node_sampler["Example sampler<br/>[json_sampler.py]"]
  node_prompt["Prompt builder<br/>[generate_prompt.py]"]
  node_ollama_client["Synthetic generator"]
end

subgraph group_preparation["Dataset preparation"]
  node_extractor["JSON extractor<br/>[extract_json.py]"]
  node_mapping_extractor["Mapping extractor"]
  node_metadata["Domain metadata updater"]
end

subgraph group_quality["Dataset quality"]
  node_data_tool["Dataset reader and validator<br/>[data_tool.py]"]
  node_validator["Validation command<br/>[validate_data.py]"]
end

subgraph group_operations["Dataset operations"]
  node_merge["Dataset merger<br/>[merge_data.py]"]
  node_stats["Dataset statistics<br/>[stat_data.py]"]
end

node_user(("Data author"))
node_seed["Seed examples"]
node_ollama["Ollama model service"]
node_generated["Generated JSON"]
node_training["Fine-tuning workflow"]

node_user -->|"requests generation"| node_ollama_client
node_seed -->|"provides examples"| node_prompt
node_prompt -->|"samples examples"| node_sampler
node_ollama_client -->|"builds prompt"| node_prompt
node_ollama_client -->|"posts generation request"| node_ollama
node_ollama -->|"returns response"| node_ollama_client
node_ollama_client -->|"prints parsed JSON"| node_generated
node_user -->|"extracts JSON"| node_mapping_extractor
node_mapping_extractor -->|"parses code blocks"| node_extractor
node_mapping_extractor -->|"validates entries"| node_data_tool
node_user -->|"updates dataset"| node_metadata
node_user -->|"checks dataset"| node_validator
node_validator -->|"reads and validates"| node_data_tool
node_user -->|"merges files"| node_merge
node_merge -->|"merges and writes"| node_data_tool
node_user -->|"summarizes dataset"| node_stats
node_stats -->|"reads and counts"| node_data_tool
node_generated -.->|"may supply training data"| node_training

click node_sampler "https://github.com/queelius/elasticsearch-lm/blob/main/json_sampler.py"
click node_prompt "https://github.com/queelius/elasticsearch-lm/blob/main/generate_prompt.py"
click node_ollama_client "https://github.com/queelius/elasticsearch-lm/blob/main/generate_synthetic_data.py"
click node_extractor "https://github.com/queelius/elasticsearch-lm/blob/main/extract_json.py"
click node_mapping_extractor "https://github.com/queelius/elasticsearch-lm/blob/main/extract_json_mapping.py"
click node_metadata "https://github.com/queelius/elasticsearch-lm/blob/main/add_meta_from_domain.py"
click node_data_tool "https://github.com/queelius/elasticsearch-lm/blob/main/data_tool.py"
click node_validator "https://github.com/queelius/elasticsearch-lm/blob/main/validate_data.py"
click node_merge "https://github.com/queelius/elasticsearch-lm/blob/main/merge_data.py"
click node_stats "https://github.com/queelius/elasticsearch-lm/blob/main/stat_data.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sampler,node_prompt,node_ollama_client toneBlue
class node_extractor,node_mapping_extractor,node_metadata toneAmber
class node_data_tool,node_validator toneMint
class node_merge,node_stats toneRose
class node_user,node_seed,node_ollama,node_generated,node_training toneIndigo
```

## Components

### Synthetic generation

- [Example sampler](https://github.com/queelius/elasticsearch-lm/blob/main/json_sampler.py): `json_sampler.py`
- [Prompt builder](https://github.com/queelius/elasticsearch-lm/blob/main/generate_prompt.py): `generate_prompt.py`
- [Synthetic generator](https://github.com/queelius/elasticsearch-lm/blob/main/generate_synthetic_data.py): `generate_synthetic_data.py`

### Dataset preparation

- [JSON extractor](https://github.com/queelius/elasticsearch-lm/blob/main/extract_json.py): `extract_json.py`
- [Mapping extractor](https://github.com/queelius/elasticsearch-lm/blob/main/extract_json_mapping.py): `extract_json_mapping.py`
- [Domain metadata updater](https://github.com/queelius/elasticsearch-lm/blob/main/add_meta_from_domain.py): `add_meta_from_domain.py`

### Dataset quality

- [Dataset reader and validator](https://github.com/queelius/elasticsearch-lm/blob/main/data_tool.py): `data_tool.py`
- [Validation command](https://github.com/queelius/elasticsearch-lm/blob/main/validate_data.py): `validate_data.py`

### Dataset operations

- [Dataset merger](https://github.com/queelius/elasticsearch-lm/blob/main/merge_data.py): `merge_data.py`
- [Dataset statistics](https://github.com/queelius/elasticsearch-lm/blob/main/stat_data.py): `stat_data.py`

### Other components

- **Data author**
- **Seed examples**
- **Ollama model service**
- **Generated JSON**
- **Fine-tuning workflow**

## Connections

- Data author → Synthetic generator: requests generation (evidence: `generate_synthetic_data.py`)
- Seed examples → Prompt builder: provides examples (evidence: `generate_prompt.py`)
- Prompt builder → Example sampler: samples examples (evidence: `generate_prompt.py`)
- Synthetic generator → Prompt builder: builds prompt (evidence: `generate_synthetic_data.py`)
- Synthetic generator → Ollama model service: posts generation request (evidence: `generate_synthetic_data.py`)
- Ollama model service → Synthetic generator: returns response (evidence: `generate_synthetic_data.py`)
- Synthetic generator → Generated JSON: prints parsed JSON (evidence: `generate_synthetic_data.py`)
- Data author → Mapping extractor: extracts JSON (evidence: `extract_json_mapping.py`)
- Mapping extractor → JSON extractor: parses code blocks (evidence: `extract_json_mapping.py`)
- Mapping extractor → Dataset reader and validator: validates entries (evidence: `extract_json_mapping.py`)
- Data author → Domain metadata updater: updates dataset (evidence: `add_meta_from_domain.py`)
- Data author → Validation command: checks dataset (evidence: `validate_data.py`)
- Validation command → Dataset reader and validator: reads and validates (evidence: `validate_data.py`)
- Data author → Dataset merger: merges files (evidence: `merge_data.py`)
- Dataset merger → Dataset reader and validator: merges and writes (evidence: `merge_data.py`)
- Data author → Dataset statistics: summarizes dataset (evidence: `stat_data.py`)
- Dataset statistics → Dataset reader and validator: reads and counts (evidence: `stat_data.py`)
- Generated JSON → Fine-tuning workflow: may supply training data (evidence: `README.md`)
