> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorpro.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Building context

> Get the right memory for each model call, with or without a project, and search memory directly.

Before each model call, your app asks EDN for the memory relevant to the user's
message. This guide shows the common cases. For what each response field
means, see [The SIP](https://docs.tensorpro.ai/concepts/sip.md).

The examples use the `EDN_API_KEY` and `EDN_SESSION_ID` environment variables
from the [Quickstart](https://docs.tensorpro.ai/quickstart.md#1-create-an-api-key), and this setup:

```python Python theme={"theme":"github-light"}
import os
import requests

EDN = "https://api.tensorpro.ai/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['EDN_API_KEY']}"}
session_id = os.environ["EDN_SESSION_ID"]
user_text = "Who manages the website project?"
```

```typescript TypeScript theme={"theme":"github-light"}
const EDN = "https://api.tensorpro.ai/api/v1";
const HEADERS = {
  Authorization: `Bearer ${process.env.EDN_API_KEY}`,
  "Content-Type": "application/json",
};
const sessionId = process.env.EDN_SESSION_ID;
const userText = "Who manages the website project?";
```

## Get context for a turn

Build a SIP with the user's latest message, then put `sip` in your model's
system prompt:

```bash cURL theme={"theme":"github-light"}
curl https://api.tensorpro.ai/api/v1/sip/build \
  -H "Authorization: Bearer $EDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "Who manages the website project?", "session_id": "'"$EDN_SESSION_ID"'"}'
```

```python Python theme={"theme":"github-light"}
sip = requests.post(
    f"{EDN}/sip/build",
    headers=HEADERS,
    json={"query": user_text, "session_id": session_id},
).json()

system_prompt = "You are a helpful assistant."
if sip["sip"]:
    system_prompt += "\n\nUse this memory about the user when it is relevant:\n\n" + sip["sip"]
```

```typescript TypeScript theme={"theme":"github-light"}
const sip = await (
  await fetch(`${EDN}/sip/build`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify({ query: userText, session_id: sessionId }),
  })
).json();

let systemPrompt = "You are a helpful assistant.";
if (sip.sip) {
  systemPrompt += `\n\nUse this memory about the user when it is relevant:\n\n${sip.sip}`;
}
```

If `sip` is empty, there is no relevant memory, so call your model without it.

## Get context from a project

To answer from one project's memory and documents, add `project_id`. Add
`include_global: true` if general memory should be included too:

```bash cURL theme={"theme":"github-light"}
curl https://api.tensorpro.ai/api/v1/sip/build \
  -H "Authorization: Bearer $EDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Who manages the website project?",
    "session_id": "'"$EDN_SESSION_ID"'",
    "project_id": "YOUR_PROJECT_ID",
    "include_global": false
  }'
```

```python Python theme={"theme":"github-light"}
sip = requests.post(
    f"{EDN}/sip/build",
    headers=HEADERS,
    json={
        "query": user_text,
        "session_id": session_id,
        "project_id": project_id,
        "include_global": False,
    },
).json()
```

```typescript TypeScript theme={"theme":"github-light"}
const sip = await (
  await fetch(`${EDN}/sip/build`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify({
      query: userText,
      session_id: sessionId,
      project_id: projectId,
      include_global: false,
    }),
  })
).json();
```

Project builds number their sources, so ask your model to cite them:

```python Python theme={"theme":"github-light"}
system_prompt = (
    "Answer using only the sources below. Cite each source you use with its "
    "number, for example [1].\n\n" + sip["sip"]
)
```

```typescript TypeScript theme={"theme":"github-light"}
const systemPrompt =
  "Answer using only the sources below. Cite each source you use with its " +
  `number, for example [1].\n\n${sip.sip}`;
```

Use `citations` to show each number's source to your user. See
[Citations](https://docs.tensorpro.ai/concepts/sip.md#citations).

## Help with follow-up questions

Short follow-ups like "and who approves it?" have little to search on. Save
each message to the session as the conversation goes:

```bash cURL theme={"theme":"github-light"}
curl https://api.tensorpro.ai/api/v1/sessions/$EDN_SESSION_ID/messages \
  -H "Authorization: Bearer $EDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"role": "user", "content": "Who manages the website project?"}'
```

```python Python theme={"theme":"github-light"}
requests.post(
    f"{EDN}/sessions/{session_id}/messages",
    headers=HEADERS,
    json={"role": "user", "content": user_text},
)
```

```typescript TypeScript theme={"theme":"github-light"}
await fetch(`${EDN}/sessions/${sessionId}/messages`, {
  method: "POST",
  headers: HEADERS,
  body: JSON.stringify({ role: "user", content: userText }),
});
```

If a question on its own finds no relevant facts, EDN retries once using the
user's recent saved messages.

## Search memory directly

To look up memory without building a SIP, for example for a search box in your
app, use `GET /api/v1/retrieval/search`:

```bash cURL theme={"theme":"github-light"}
curl "https://api.tensorpro.ai/api/v1/retrieval/search?q=website%20project&limit=5" \
  -H "Authorization: Bearer $EDN_API_KEY"
```

```python Python theme={"theme":"github-light"}
results = requests.get(
    f"{EDN}/retrieval/search",
    headers=HEADERS,
    params={"q": "website project", "limit": 5},
).json()
```

```typescript TypeScript theme={"theme":"github-light"}
const results = await (
  await fetch(`${EDN}/retrieval/search?q=${encodeURIComponent("website project")}&limit=5`, {
    headers: HEADERS,
  })
).json();
```

```json Response (shortened) theme={"theme":"github-light"}
{
  "records": [
    {
      "id": "ef771387-4412-4784-a94c-73c819991fad",
      "content_summary": "Sara manages the website project.",
      "provenance": "USER_STATED",
      "domain": "factual",
      "similarity": 0.70,
      "created_at": "2026-11-10T06:36:10+00:00"
    }
  ],
  "count": 1
}
```

* Results are ordered by `similarity`; higher means a closer match.
* `limit` defaults to 10. Values above 50 are treated as 50.
* Search covers **general memory only**, not project memory, and only records
  that can be used as context.

## Next steps

> [card] [The SIP](https://docs.tensorpro.ai/concepts/sip.md)
>
> Every response field explained.

> [card] [Writing memory](https://docs.tensorpro.ai/guides/writing-memory.md)
>
> Save each turn after the model replies.

> [card] [Quickstart](https://docs.tensorpro.ai/quickstart.md)
>
> The full loop in five minutes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.