Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The following Python example prepares that context. It uses the client, `SESSION
session = agent_memory.get_session_memory(session_id=SESSION_ID)
memories = agent_memory.search_long_term_memory(
request={
"text": question,
"query": question,
"filter_": {"owner_id": {"eq": USER_ID}},
"limit": 5,
},
Expand Down Expand Up @@ -183,7 +183,7 @@ The ingestion-hook `503` retry error and `422` stopped error also have distinct

Create memories directly when your application already has information to store, such as a preference submitted through a form. Set the owner and a stable record ID. Creating an eligible record with the same ID again replaces it; access checks and protection for document-managed records still apply. Check the bulk response for per-record errors. Direct creation does not apply automatic extraction or sensitive-data exclusions.

See [Long-term memory]({{< relref "/develop/ai/context-engine/agent-memory/memories" >}}) for creation methods, search fields, retention, and extraction controls.
See [Long-term memory]({{< relref "/develop/ai/context-engine/agent-memory/long-term-memory" >}}) for creation methods, search fields, retention, and extraction controls.

For unstructured documents, use [MemoryETL](/content/develop/ai/context-engine/agent-memory/memory-etl.md) to configure an extractor, submit a revision, and track its outputs. Source links let you trace extracted memories back to document or session inputs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def main():
page = await memory.list_ingestion_hook_statuses_async(
limit=20, cursor=cursor, http_headers=headers,
)
for status in page.statuses:
for status in page.items:
print(status.model_dump_json(by_alias=True))
cursor = page.next_cursor
if not cursor:
Expand Down Expand Up @@ -310,7 +310,7 @@ async function main() {
let cursor: string | undefined;
do {
const page = await memory.listIngestionHookStatuses(20, cursor, options);
console.dir(page.statuses, { depth: null });
console.dir(page.items, { depth: null });
cursor = page.nextCursor;
} while (cursor);
}
Expand Down Expand Up @@ -343,7 +343,7 @@ fi

{{< /multitabs >}}

Lists return `statuses` and `nextCursor`. Pass `nextCursor` as `cursor`, even when the page is empty; ownership filtering can produce that result. Keep the same store, credential, and list parameters. The maximum page size is 100.
Lists return `items` and `nextCursor`. Pass `nextCursor` as `cursor`, even when the page is empty; ownership filtering can produce that result. Keep the same store, credential, and list parameters. The maximum page size is 100.

Private pending content expires within 24 hours or the earlier operation deadline. Compact status and write receipts remain for seven days after completion or expiry. Status omits private input, generated content, prompts, endpoint configuration, and keys.

Expand Down
23 changes: 11 additions & 12 deletions content/develop/ai/context-engine/agent-memory/long-term-memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Omit `query` to retrieve records by filters without a semantic query. For exampl
recent_memories = agent_memory.search_long_term_memory(request={
"filter_": {"owner_id": {"eq": USER_ID}},
"sort_by": "updatedAt",
"sort_order": "desc",
"sort_order": "DESC",
"limit": 10,
})
show("Recent memories", recent_memories)
Expand All @@ -99,7 +99,7 @@ Omit `query` to retrieve records by filters without a semantic query. For exampl
```typescript
const recentMemories = await agentMemory.searchLongTermMemory({
filter: { ownerId: { eq: userId } },
sortBy: "updatedAt", sortOrder: "desc", limit: 10,
sortBy: "updatedAt", sortOrder: "DESC", limit: 10,
});
console.dir(recentMemories, { depth: null });
```
Expand Down Expand Up @@ -201,8 +201,8 @@ After enabling the type, add a travel message to a new session. Run this write o
-tab-sep-

```typescript
await agentMemory.addSessionEvent({
sessionId: "trip-preference-session", actorId: userId, role: "USER",
await agentMemory.addSessionEvent("trip-preference-session", {
actorId: userId, role: "USER",
content: [{ text: "I am visiting Tokyo and Kyoto next month. I am vegetarian." }],
createdAt: new Date(),
});
Expand All @@ -228,7 +228,7 @@ Search for the structured memory:
```python
custom_results = agent_memory.search_long_term_memory(
request={
"text": "What are the requirements for the user's trip?",
"query": "What are the requirements for the user's trip?",
"filter_": {
"owner_id": {"eq": USER_ID},
"memory_type": {"eq": "trip_preference"},
Expand All @@ -243,7 +243,7 @@ Search for the structured memory:

```typescript
const customResults = await agentMemory.searchLongTermMemory({
text: "What are the requirements for the user's trip?",
query: "What are the requirements for the user's trip?",
filter: {
ownerId: { eq: userId },
memoryType: { eq: "trip_preference" },
Expand Down Expand Up @@ -357,7 +357,7 @@ If your application already has structured trip data, write it directly using th

```python
direct_result = agent_memory.bulk_create_long_term_memories(memories=[{
"memoryId": "trip-form-1",
"memory_id": "trip-form-1",
"text": "The user plans to visit Tokyo and Kyoto next month and requires vegetarian food.",
"owner_id": USER_ID,
"memory_type": "trip_preference",
Expand All @@ -376,7 +376,7 @@ If your application already has structured trip data, write it directly using th
```typescript
const directResult = await agentMemory.bulkCreateLongTermMemories({
memories: [{
id: "trip-form-1",
memoryId: "trip-form-1",
text: "The user plans to visit Tokyo and Kyoto next month and requires vegetarian food.",
ownerId: userId,
memoryType: "trip_preference",
Expand Down Expand Up @@ -456,8 +456,7 @@ The semantic exclusion prompt tells Redis Agent Memory which information should
-tab-sep-

```typescript
const sensitiveEvent = await agentMemory.addSessionEvent({
sessionId,
const sensitiveEvent = await agentMemory.addSessionEvent(sessionId, {
actorId: userId,
role: "USER",
content: [{
Expand Down Expand Up @@ -502,7 +501,7 @@ Run the event write once. In the SDK files, comment out event creation and its o
```python
exclusion_results = agent_memory.search_long_term_memory(
request={
"text": "Where is the user staying in Tokyo?",
"query": "Where is the user staying in Tokyo?",
"filter_": {
"owner_id": {"eq": USER_ID},
},
Expand All @@ -516,7 +515,7 @@ Run the event write once. In the SDK files, comment out event creation and its o

```typescript
const exclusionResults = await agentMemory.searchLongTermMemory({
text: "Where is the user staying in Tokyo?",
query: "Where is the user staying in Tokyo?",
filter: {
ownerId: { eq: userId },
},
Expand Down
79 changes: 39 additions & 40 deletions content/develop/ai/context-engine/agent-memory/memory-etl.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ async def main():
ingestion_id=ingestion_id, http_headers=headers,
)
status = record.ingestion.status
if status.processing in {"succeeded", "partial", "failed"}:
if status.processing in {"SUCCEEDED", "PARTIAL", "FAILED"}:
print(status.model_dump_json(by_alias=True))
break
await asyncio.sleep(2)
else:
raise TimeoutError(f"Continue polling ingestion {ingestion_id}")

offset = 0
cursor = None
while True:
page = await memory.list_document_ingestion_outputs_async(
ingestion_id=ingestion_id, limit=100, offset=offset, http_headers=headers,
ingestion_id=ingestion_id, limit=100, cursor=cursor, http_headers=headers,
)
if not page.memory_ids:
print(page.items)
cursor = page.next_cursor
if not cursor:
break
print(page.memory_ids)
offset += len(page.memory_ids)
if status.processing != "succeeded":
if status.processing != "SUCCEEDED":
raise RuntimeError(f"Inspect ingestion {ingestion_id}: {status.processing}")


Expand Down Expand Up @@ -140,7 +140,7 @@ async function main() {
let processing: string | undefined;
for (let attempt = 0; attempt < 60; attempt++) {
const { ingestion } = await memory.getDocumentIngestion(ingestionId, options);
if (["succeeded", "partial", "failed"].includes(ingestion.status.processing)) {
if (["SUCCEEDED", "PARTIAL", "FAILED"].includes(ingestion.status.processing)) {
processing = ingestion.status.processing;
console.dir(ingestion.status, { depth: null });
finished = true;
Expand All @@ -149,14 +149,13 @@ async function main() {
await delay(2000);
}
if (!finished) throw new Error(`Continue polling ingestion ${ingestionId}`);
let offset = 0;
for (;;) {
const page = await memory.listDocumentIngestionOutputs(ingestionId, 100, offset, options);
if (!page.memoryIds.length) break;
console.log(page.memoryIds);
offset += page.memoryIds.length;
}
if (processing !== "succeeded") throw new Error(`Inspect ingestion ${ingestionId}: ${processing}`);
let cursor: string | undefined;
do {
const page = await memory.listDocumentIngestionOutputs(ingestionId, 100, cursor, options);
console.log(page.items);
cursor = page.nextCursor;
} while (cursor);
if (processing !== "SUCCEEDED") throw new Error(`Inspect ingestion ${ingestionId}: ${processing}`);
}

main().catch((error) => { console.error(error instanceof Error ? error.message : "Request failed"); process.exitCode = 1; });
Expand Down Expand Up @@ -243,34 +242,34 @@ Set `MEMORY_ID` to one returned output ID. These examples follow both source pag
{{< multitabs id="document-provenance" tab1="Python" tab2="TypeScript" tab3="curl" >}}

```python
source_page_token = None
source_cursor = None
while True:
links = await memory.list_memory_source_links_async(
memory_id=os.environ["MEMORY_ID"], limit=100,
page_token=source_page_token, http_headers=headers,
cursor=source_cursor, http_headers=headers,
)
for source in links.items:
print(source.model_dump_json(by_alias=True))
evidence_token = source.evidence_next_page_token
while evidence_token:
evidence_cursor = source.evidence_next_cursor
while evidence_cursor:
evidence = await memory.list_memory_source_evidence_async(
memory_id=os.environ["MEMORY_ID"], source_id=source.source_id,
limit=100, page_token=evidence_token, http_headers=headers,
limit=100, cursor=evidence_cursor, http_headers=headers,
)
print(evidence.source.model_dump_json(by_alias=True))
evidence_token = evidence.source.evidence_next_page_token
reverse_token = None
evidence_cursor = evidence.source.evidence_next_cursor
reverse_cursor = None
while True:
related = await memory.list_source_memories_async(
source_id=source.source_id, owner_id=os.environ["OWNER_ID"],
limit=100, page_token=reverse_token, http_headers=headers,
limit=100, cursor=reverse_cursor, http_headers=headers,
)
print(related.model_dump_json(by_alias=True))
reverse_token = related.next_page_token
if not reverse_token:
reverse_cursor = related.next_cursor
if not reverse_cursor:
break
source_page_token = links.next_page_token
if not source_page_token:
source_cursor = links.next_cursor
if not source_cursor:
break
```

Expand All @@ -279,30 +278,30 @@ Set `MEMORY_ID` to one returned output ID. These examples follow both source pag
```typescript
const memoryId = process.env.MEMORY_ID;
if (!memoryId) throw new Error("Set MEMORY_ID to an output memory ID.");
let sourcePageToken: string | undefined;
let sourceCursor: string | undefined;
do {
const links = await memory.listMemorySourceLinks(memoryId, 100, sourcePageToken, options);
const links = await memory.listMemorySourceLinks(memoryId, 100, sourceCursor, options);
for (const source of links.items) {
console.dir(source, { depth: null });
let evidenceToken = source.evidenceNextPageToken;
while (evidenceToken) {
let evidenceCursor = source.evidenceNextCursor;
while (evidenceCursor) {
const evidence = await memory.listMemorySourceEvidence(
memoryId, source.sourceId, 100, evidenceToken, options,
memoryId, source.sourceId, 100, evidenceCursor, options,
);
console.dir(evidence.source, { depth: null });
evidenceToken = evidence.source.evidenceNextPageToken;
evidenceCursor = evidence.source.evidenceNextCursor;
}
let reverseToken: string | undefined;
let reverseCursor: string | undefined;
do {
const related = await memory.listSourceMemories(
source.sourceId, OWNER_ID, 100, reverseToken, options,
source.sourceId, OWNER_ID, 100, reverseCursor, options,
);
console.dir(related.items, { depth: null });
reverseToken = related.nextPageToken;
} while (reverseToken);
reverseCursor = related.nextCursor;
} while (reverseCursor);
}
sourcePageToken = links.nextPageToken;
} while (sourcePageToken);
sourceCursor = links.nextCursor;
} while (sourceCursor);
```

-tab-sep-
Expand Down
Loading
Loading