sources: in ladygraph.yaml has a name (a label for logs), a kind, a scheme (how passage addresses start, such as notes://), and the settings of its kind.
A source of a kind with no adapter is skipped with a warning, not an error. Check the log if a source seems missing.
What you can read from
ladyGraph indexes business internal documents: skills, policies and guidelines, and business-application configurations. Each kind of system reaches the index through a source.
The Interfaces page shows the
Source contract.
One example of each kind
This block is tested:tests/test_project_paths.py loads it with load_sources. The list goes under sources:.
SQL sources
Akind: sql source declares four things: where to connect (connections), which tables it mines (tables, and optionally relationships), the queries that read them (queries), and how query columns become Document fields (map).
- The manifest must be cheap. It returns
unit, a version column or checksum, and the same metadata and date columns asdocument. Otherwise every update sees a change. - Parameters are bound. Queries use
:scopeand:unit, never formatted text. Table and column names come from this trusted config, never from user input. - Two databases cannot be joined in SQL. The adapter runs the
documentandpassagesqueries separately and joins them onunitin Python. AJOINinside a query works only between tables on the same connection. mapsupplies the title, metadata, access labels, validity dates, the version parts, and the passage text, anchor and section. The adapter computes the rest:scopeandunitfrom the manifest columns,shapefrom the config, and the addresses.- Two schemes.
schemeaddresses passages (db://).document_schemeaddresses the document (dbdoc://). Whendocument_schemeis absent, the document usesscheme. passages_digestkeeps the manifest cheap.DocVersion.passagesmust be the same frommanifestandread. With the digest query, both use the database’s own hash of the chunk texts, so no text is read to detect a change.relationshipsis declarative. Nothing in SQL enforces it. It documents the keys and cardinality, and tells the adapter to read the latest version only (pick: latest). It is not needed to run the queries.replacementsis an optional query. It takes:scopeand returns each unit with the effective date of a document that replaces it. The unit’s validity period ends at the earlier of its expiry and that date.
Config and markdown sources
Business configuration has no fixed shape: routing rules, escalation rules, a glossary, skill routing, and notes written as markdown. Three sources read it without a database. Each flattens and normalizes its input into Records, because the extractor needs the same thing from all of it: a title, metadata, and passages of plain text it can quote.
Normalizing removes what is not knowledge. Text is NFC and trimmed, numbers and dates become text, booleans become “yes” and “no”, and empty values are dropped. Nested objects become
a.b: value lines, and lists of scalars become a: x; y. The output is deterministic, because the resolver reads it again at search time and compares fingerprints.
A new kind of input needs only a Flattener, a function flatten(scope, raw) that returns Records. FlatSource is the only source that reads Records, so versions, validity periods and addresses are computed in one place.
Rules
For JSON and pydantic sources, rules pick the entries with a JSON Pointer and say how to read them. Write one rule per kind of entry.
A unit is
<path before the entry>~<slug of the id>, so reordering a list changes nothing. Two entries with the same id both stay, with a -2 suffix. Without rules, every top-level member of the input is one entry.
This is a routing rule from a blueprint, and what the extractor receives:
PYTHONPATH=. python ladygraph/tutorial/04_sources/hello_flat_sources.py from ladyGraph/ to see all of this on sample data.
Automatic mode
A real blueprint is mostly plumbing, such as thresholds, switches, budgets and refresh intervals, with a little knowledge in a few recognizable shapes. Writing a rule per kind of entry does not scale to files nobody controls.auto: {} on a JSON or pydantic source finds the knowledge from the shape of the data and says why.
- Every object in a list is an entry (a rule, a term, a field, a block). The rest of the file is one profile entry.
- Each leaf is scored from the kind of value and from its field name. A number, a switch or a code word explains nothing. A phrase, a sentence or a list of phrases does. Names like
label,markersandaliaseslean to knowledge. Names likeenabledandmax_rowslean to configuration. - A leaf that points at another entry scores more, because it explains why the neighbors are related.
- Entries marked
kind: secretorvisibility: restrictedare skipped. A long text built from smaller texts is dropped as a copy. An entry left with only its label is dropped. a & b & !cmarkers are written as words, and an id that refers to an entry is written as its title.
--misses lists the fields that were dropped although their value reads as language, and exits with status 1 when there are any. A name you list in knowledge_names always counts as knowledge.
Run these modules as
python -m sources.<module> with the ladygraph/ folder on PYTHONPATH, as above, or import sources.<module>. Never run them from inside the sources/ folder, whose json.py and pydantic.py would hide the standard json module.Declared concepts
An entry that a person already described does not need a model. A routing rule, a glossary term or a taxonomy has a name and the words people use for it, and an LLM only turns those into fragments. Withauto, an entry that has a title and keyword lists but no prose is declared, and DeclaredExtractor makes exactly one concept from it, with no LLM call.
- The title is the concept.
- The keywords and aliases are its user words, stamped as human-declared.
- Its description repeats a sample of the keywords, so the vector and the decider read them too.
a & b & !c clauses. Entries with prose still go to the LLM, so one source can hold both: DeclaredOrLlm(DeclaredExtractor(...), LlmOkfExtractor(...)). Set the ontology type of declared concepts with auto: {types: {"query route rules": routing}}.
On the sample blueprint, 6 of 8 entries cost no LLM calls.
Contact details
An e-mail address or phone number is context for a concept, not a concept. An extractor refuses a candidate whose name or quote is only a contact detail. The sentence that holds one becomes extra evidence of the larger concept it elaborates, with no model call. A hit shows it when more than one evidence pointer is asked for (SearchConfig.max_evidence). To keep contact details away from a model, mask them with auto: {redact: [email, phone]}. Masking is off by default.
Triage
Listingexclude: fields by hand does not scale either, so a decision model can judge them. Add triage: {cache: triage.json} and run this once:
notify of an escalation rule: it holds an e-mail address. Knowledge or a setting?”. The answers go into triage.json, one per kind of field and not per value. Every later run reads that file and calls no model.
The saved file is what keeps the index correct. Flattened text is fingerprinted and read again at search time, so a model that answered differently on a later run would make valid evidence look stale. Review the file and change keep to override a decision, or delete an entry to decide it again. A field is dropped only when the model is confident it is a setting (drop_threshold, default 0.7). An unsure answer or a model error keeps the field.
Reading an entry as prose
A flattened entry islabel: value lines. A rule, or auto:, with rewrite: true makes ReadingExtractor ask the LLM, once per entry, to write it as cohesive prose. The extractor reads that text next to the passages. It is context and never evidence: quotes must still be copied from the passages.
Text in quotation marks is what a person wrote as a term. Each quoted term becomes a user word on the concept whose evidence is nearest. Give ReadingExtractor its own client with a small max_output_tokens.
Markdown
A markdown file keeps its words as written. Front matter gives the title, validity, access labels and metadata. Headings split the file into Documents atsplit_level, and a code fence or table stays in one block.
The
file version hashes the title, anchors and text, so any edit replaces the unit. The metadata version hashes metadata, access labels and validity, so a change there only re-opens context choices.
pydantic
provider: package.module:function is called with the scope and returns a model. It is dumped with model_dump(mode="json"), so the same rules work on a file or on the model. Values equal to their default stay, because a default such as route: direct is still a setting. Set exclude_defaults: true to leave them out. In a host application, a provider such as host_app.services.settings:load_settings reads the live settings of a domain.
Several sources in one scope
run_update compares a source’s manifest with every unit stored in the scope. A second source run into the same scope would see the first one’s units as deleted and drop them. Present them as one with CombinedSource(*sources) from sources/combined.py. Two sources must not produce the same unit.
Long text: chunking
A long, loosely structured text, such as OCR or a converted PDF, needs cutting into passages that know their heading path. Putchunking: on a markdown source entry.
Entity kinds
An optionalentities: section names things a deployment’s documents contain and explains them: document codes, form codes, decision numbers and abbreviations. A kind is data, so a new kind is a new entry in the config. See Entity kinds.