Sessions¶
Interaction modes for the Brain. The Circuit is the universal backend; Sessions define how you interact with it.
RetrievalResult
dataclass
¶
RetrievalResult(neuron_id: str, score: float, content: str, context_ids: list[str] = list(), sources: list[Source] = list())
A single retrieval result with metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
neuron_id |
str
|
The matched neuron's ID. |
score |
float
|
Relevance score (higher = better). |
content |
str
|
Neuron content (Markdown). |
context_ids |
list[str]
|
IDs of ensemble neighbors (N-hop context). |
sources |
list[Source]
|
Source records attached to this neuron (for citation). |
Session ¶
Bases: ABC
Abstract base for Brain interaction sessions.
All sessions wrap a Circuit and can be
either persistent (changes committed on close) or ephemeral
(changes discarded on close).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
Circuit
|
The Circuit to interact with. |
required |
persist
|
bool
|
Whether to commit changes on close. |
True
|
QABotSession ¶
QABotSession(circuit: Circuit, *, persist: bool = True, learning_rate: float = 0.1, exclude_seen: bool = True)
Bases: Session
RAG chat session with self-optimizing retrieval.
Provides intelligent retrieval that improves during the conversation:
- Negative feedback: follow-up similar queries penalize prior results
- Deduplication: already-returned neurons are excluded
- Accept: explicit positive feedback boosts neurons
- Persistent/ephemeral: choose whether to commit boosts on close
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
Circuit
|
The Circuit (must have an embedder configured). |
required |
persist
|
bool
|
Commit retrieval boosts on close. |
True
|
learning_rate
|
float
|
Feedback strength (default |
0.1
|
exclude_seen
|
bool
|
Skip already-returned neurons (default |
True
|
ask
async
¶
Ask a question. Returns scored, deduplicated results.
Automatically applies negative feedback if this is a follow-up to a similar prior query (implicit signal that prior results were insufficient).
accept
async
¶
Mark neurons as helpful (positive feedback).
Boosts retrieval_boost with diminishing returns.
IngestSession ¶
IngestSession(circuit: Circuit, *, persist: bool = True, auto_relate: bool = True, auto_relate_limit: int = 5)
Bases: Session
Conversational knowledge curation session.
Lets a user (or agent) build and refine the knowledge graph through dialogue: add neurons, discover related concepts, create synapses, and merge duplicates. This is how conversational RAG curation works — the conversation directly improves retrieval quality by curating the graph structure.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
Circuit
|
The Circuit to curate. |
required |
persist
|
bool
|
Commit retrieval boosts on close. |
True
|
auto_relate
|
bool
|
Automatically search for related neurons on ingest. |
True
|
auto_relate_limit
|
int
|
Max related neurons returned by ingest. |
5
|
ingest
async
¶
ingest(content: str, *, type: str | None = None, domain: str | None = None, source: str | None = None, source_meta: Source | None = None, id: str | None = None) -> tuple[Neuron, list[Neuron]]
Add a neuron and discover related existing knowledge.
Creates the neuron, auto-embeds it (if an embedder is configured), and searches for related neurons via graph-weighted retrieval.
When source_meta is provided, the source is deduplicated by URL,
created if new, and attached to the new neuron.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Markdown content for the new neuron. |
required |
type
|
str | None
|
Category tag (e.g. |
None
|
domain
|
str | None
|
Knowledge domain (e.g. |
None
|
source
|
str | None
|
Origin URL or reference (legacy string field). |
None
|
source_meta
|
Source | None
|
Structured Source for citation tracking. |
None
|
id
|
str | None
|
Custom neuron ID (auto-generated if |
None
|
Returns:
| Type | Description |
|---|---|
Neuron
|
Tuple of |
list[Neuron]
|
|
relate
async
¶
relate(a: str, b: str, type: SynapseType = SynapseType.RELATES_TO, *, weight: float = 0.5) -> list[Synapse]
Create or strengthen a synapse between two neurons.
If the synapse already exists, its weight is increased by 0.1
(capped at plasticity.weight_ceiling). Bidirectional types
create edges in both directions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
str
|
Source neuron ID. |
required |
b
|
str
|
Target neuron ID. |
required |
type
|
SynapseType
|
Connection semantics (default |
RELATES_TO
|
weight
|
float
|
Initial weight for new synapses. |
0.5
|
Returns:
| Type | Description |
|---|---|
list[Synapse]
|
List of created or updated synapses. |
search
async
¶
Search existing knowledge using graph-weighted retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search text. |
required |
limit
|
int
|
Maximum results. |
10
|
Returns:
| Type | Description |
|---|---|
list[Neuron]
|
Matching neurons sorted by relevance. |
merge
async
¶
Merge source neurons into a target neuron.
Transfers all synapses from source neurons to the target,
appends their content with --- separators, then removes
the source neurons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_ids
|
list[str]
|
IDs of neurons to merge (will be deleted). |
required |
into_id
|
str
|
ID of the target neuron (will be preserved). |
required |
Returns:
| Type | Description |
|---|---|
Neuron
|
The updated target neuron with merged content. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target neuron does not exist. |
TutorSession moved to spikuit_cli.tutor in v0.6.3 — the core is
LLM-free and the tutor orchestration belongs with the CLI.
TutorSession ¶
Interprets an ExamPlan.
record_response
async
¶
Grade the current step's quiz and return the next transition.
record_llm_graded
async
¶
Accept a pre-graded QuizResult (from an LLMGrader) for the
current step. Used when Quiz.grade() returned
needs_tutor_grading=True.
record_follow_up
async
¶
Record a follow-up result and either emit the next follow-up or advance past the step.
FollowUpResult is a distinct type from QuizResult — by design, these never reach circuit.fire.
close
async
¶
End the session. Any in-flight step with no grade is fired as MISS (matches legacy TutorSession behavior).
advance
async
¶
Commit the current step (fire FSRS) and advance the cursor.
Called by the caller after handling ADVANCE / REVEAL_ANSWER
transitions. Kept separate from record_response so callers
can interleave follow-ups / UI before committing.