teff.memory.extract¶
teff.memory.extract
¶
LLM-based fact extraction for long-term memory.
The :class:MemoryExtractor turns a conversation into durable facts by
asking a model to summarise what should be remembered beyond the current
session. It is a thin layer over a :class:~teff.harness.loop.Harness:
extractcalls the model once and parses a JSON array of facts from the reply (tolerating code fences and surrounding prose).saveextracts facts and writes them into a :class:~teff.memory.base.MemoryStore, keyed by a stable hash of the fact text so re-extracting the same fact upserts it instead of duplicating it.
The extractor never stores anything itself; pass it a :class:MemoryStore
(which owns the vector store / embedder) to persist results.
Classes:
| Name | Description |
|---|---|
MemoryExtractor |
Extract durable facts from a conversation using an LLM. |
MemoryExtractor
¶
Extract durable facts from a conversation using an LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
harness
|
Harness | None
|
A :class: |
None
|
model
|
str | None
|
Model name for a self-built harness (ignored when harness is given). |
None
|
provider
|
str | None
|
Provider key for a self-built harness. |
None
|
system_prompt
|
str | None
|
Overrides the default extraction prompt. |
None
|
temperature
|
float
|
Sampling temperature for the extraction call. |
0.0
|
Methods:
| Name | Description |
|---|---|
extract |
Return the durable facts found in conversation. |
save |
Extract facts and write them into memory. |
Source code in teff/memory/extract.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
extract
async
¶
extract(conversation)
Return the durable facts found in conversation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation
|
list[dict]
|
OpenAI-style messages ( |
required |
Source code in teff/memory/extract.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
save
async
¶
save(memory, conversation, namespace, *, ttl=None)
Extract facts and write them into memory.
Each fact is stored under a stable key derived from its text (a short SHA-1), so re-extracting the same fact updates it in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory
|
Any
|
A :class: |
required |
conversation
|
list[dict]
|
The messages to extract facts from. |
required |
namespace
|
tuple[str, ...]
|
Namespace to store the facts under. |
required |
ttl
|
float | None
|
Per-item TTL in seconds, or |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
The |
Source code in teff/memory/extract.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |