Skip to content

Pipeline, modes & LLMs

RAGPipeline wires the whole flow together:

parse → retrieve → reason → prove → assemble context → generate (LLM) → firewall → RAGResult
import hypermesh as hm
from hypermesh.rag import RAGPipeline, LLMConfig
db = hm.connect("data/")
pipe = RAGPipeline(db, table="DRONES", mode="hybrid", require_proof=True,
rules=[rule], llm_config=LLMConfig.mock())
result = await pipe.query("which edges are coordinated threats?")
RAGPipeline(
db, table,
entity_map=None, openai_api_key=None, llm_config=None,
top_k=40, token_budget=3000, db_dir="",
# neuro-symbolic
mode="neuro", require_proof=False, rules=None, rule_store=None,
max_reason_iterations=64, reason_deadline_ms=None, provenance_resolver=None,
)
ParameterDefaultMeaning
dbAn open hm.Connection.
tableHyperedge table to query (e.g. "DRONES").
entity_mapauto{node_id: {type, display, short}}; auto-loaded from {db_dir}/{TABLE}_entity_map.json if omitted.
openai_api_keyenvFalls back to OPENAI_API_KEY.
llm_configOpenAIFull LLMConfig override (see below).
top_k40Max hyperedges retrieved per query.
token_budget3000Max context tokens for the hyperedge block.
db_dirHMDB_DIR/dataDB directory (locates entity maps + rule store).
mode"neuro"neuro | symbolic | hybrid. Invalid → ValueError.
require_proofFalseAbstain unless a symbolic fact is proved.
rulesNoneAd-hoc rule dicts; overrides the rule store for this pipeline.
rule_storeautoA RuleStore; defaults to RuleStore(db_dir).
max_reason_iterations64Per-stratum fixpoint cap.
reason_deadline_msNoneWall-clock budget for reasoning.
provenance_resolverNoneHook to enrich proof-leaf provenance.

Properties: pipe.table, pipe.model.

ModeReasoningLLMUse case
neurooffyesClassic RAG; exploratory Q&A, no guarantees.
symboliconnoAudit/compliance: derived facts + proofs, deterministic answer text, zero generation.
hybridonyesProduct answers: reasoning feeds the LLM, firewall gates the output.

In symbolic mode no model is called at all — the answer is rendered deterministically from the proven facts, and require_proof makes it abstain when nothing is proved.

result: RAGResult = await pipe.query("")

Runs the full flow and returns a RAGResult. Raises ValueError if the table isn’t found.

parsed, edges, token_stream = await pipe.stream("")
async for token in token_stream:
print(token, end="")

Returns (ParsedQuery, list[RetrievedEdge], AsyncIterator[str]) for token-by-token generation. Streaming is generation-only (the firewall gates whole answers), so use query() when you need the verifiability guarantees.

FieldMeaning
query / parsedInput query and parsed form.
answerFinal (firewalled) answer text.
cited_edges / all_edgesRetrievedEdges cited / retrieved.
confidence / low_confidence0.0 when abstained; low_confidence if abstained or < 0.5.
modeThe mode that ran.
abstainedTrue if the firewall abstained.
derived_factsList of {step_tag, fact, predicate, args, confidence, rule_id, rule_tag, hedge_tags}.
proofsList of proof DAGs (ProofTree.as_dict() + step_tag/rule_tag).
firewall{outcome, abstained, coverage, supported_count, stripped_count, stripped}.
rules_firedRule ids that produced facts.
modelModel name ("symbolic", "mock", "gpt-4o", …).
retrieval_ms / reasoning_ms / generation_ms / total_msStage timings.
prompt_tokens / completion_tokens / context_tokensToken accounting.
interaction_idHarvested interaction id (for feedback/training).

result.as_dict() returns the JSON form (used by the REST API).

The LLM is fully pluggable via LLMConfig. The reason → prove → firewall guarantees apply no matter which model writes the text, so a weaker/cheaper local model is still safe to deploy.

from hypermesh.rag import LLMConfig
BackendConstructorNotes
OpenAILLMConfig(model="gpt-4o", api_key=...)Default backend.
OpenAI-compatibleLLMConfig(model=..., base_url=...)vLLM, Groq, Together, Azure, llama.cpp server.
OllamaLLMConfig.ollama("phi3:mini")base_url=http://localhost:11434/v1.
LM StudioLLMConfig.lmstudio()base_url=http://localhost:1234/v1.
Local GGUFLLMConfig.llama_cpp("model.gguf")In-process; pip install llama-cpp-python.
MockLLMConfig.mock()Deterministic, offline; for tests/CI/air-gapped demos.
Custom (any protocol)LLMConfig.custom(fn)Bring-your-own — Anthropic, Gemini, a fine-tune.

chat_fn(messages, cfg) may be sync or async (sync runs off the event loop) and receives OpenAI-style [{role, content}, ...]. It must return one of:

  • a str — the answer text;
  • a dict {"text", "prompt_tokens", "completion_tokens", "model"};
  • a tuple (text, prompt_tokens, completion_tokens[, model]).
import anthropic
client = anthropic.Anthropic()
def claude(messages, cfg):
sys = next((m["content"] for m in messages if m["role"] == "system"), "")
user = [m for m in messages if m["role"] != "system"]
resp = client.messages.create(
model="claude-3-5-sonnet-latest", system=sys,
messages=[{"role": m["role"], "content": m["content"]} for m in user],
max_tokens=cfg.max_tokens,
)
return {"text": resp.content[0].text,
"prompt_tokens": resp.usage.input_tokens,
"completion_tokens": resp.usage.output_tokens,
"model": "claude-3-5-sonnet"}
pipe = RAGPipeline(db, table="DRONES", mode="hybrid", rules=[rule],
llm_config=LLMConfig.custom(claude))

Whatever the custom model emits, the firewall still strips any sentence that doesn’t cite a proven tag — the integration point cannot weaken the guarantee.

FieldDefaultMeaning
model"gpt-4o-mini"Model name / GGUF path.
base_urlOpenAIAPI base URL.
api_key""API key.
temperature0.1Low — factual, not creative.
max_tokens800Generation cap.
timeout_s60Request timeout.
backend"openai"openai | llama_cpp | mock | custom.
gguf_path""GGUF path when backend="llama_cpp".
n_gpu_layers-1-1 = all layers on GPU.
n_ctx4096Context window for llama.cpp.
chat_fnNoneCallable for backend="custom".

Next: Python API reference or the REST API.