Skip to main content

Building Layers

A Lattice is built incrementally, one layer at a time. You can call build() for a fully automated pipeline, or step through each layer manually for more control.

Layer types

Each layer controls how nodes are grouped before being passed to the LLM for synthesis.

ClassGroups byRequired metadata
SessionLayer(n=1)N consecutive sessionsinput_session
TimeLayer(by="day")Calendar period (day, week, month, year)time
NumberLayer(n=20)Fixed chunks of N nodes
AllLayer()All nodes into one group
CustomLayer(fn=...)Arbitrary splitting functiondepends on fn

Import them from lattice:

from lattice import Sequential, SessionLayer, TimeLayer, NumberLayer, AllLayer, CustomLayer

Defining a config with Sequential

Wrap your layers in a Sequential and pass it to Lattice at construction time (or assign it to l.config before calling build()):

from lattice import Sequential, SessionLayer, TimeLayer, AllLayer

config = Sequential(
TimeLayer(by="day"), # L1: one group per calendar day
AllLayer(), # L2: collapse everything into one top-level insight
)

l = Lattice(..., config=config)
await l.build()

Auto-config

If you don't want to tune the layer structure manually, auto_config() generates a Sequential based on heuristics.

l = Lattice(...)
config = l.auto_config() # infer layers
# or: l.auto_config(target_layer_num=3)
await l.build()

Custom splitting logic

Use CustomLayer when none of the built-in layers fit your grouping needs:

from lattice import CustomLayer

def split_by_topic(nodes):
# return a list of groups (each group is a list of nodes)
...

config = Sequential(CustomLayer(fn=split_by_topic), AllLayer())