Cortex Layer

Getting started

What Cortex is, the two ways to use it, and your first memory.

Cortex is a memory layer for AI agents. It stores memories as linked pages and retrieves with vector search plus link-expansion, so multi-hop facts come back without over-fetching a large top-k — ask "who directed Inception?" and get back not just that page, but the linked page about where the director was born, because the two pages share an entity.

There are two ways to run it, with the same method names and result shapes:

Quickstart: hosted

pip install cortexlayer
import os
from cortexlayer import CortexClient

client = CortexClient(api_key=os.getenv("CORTEX_API_KEY", "sk-..."))

client.add("I moved to Lisbon in March.")

results = client.search("Where does Alice live?", limit=5)
print(results)

Create a key in the Cortex web app (Keys). Full reference: Hosted / CortexClient.

Quickstart: embedded

pip install "cortexlayer[local]"
from cortexlayer import Memory

m = Memory("./cortex-data")

m.add("Christopher Nolan directed Inception.", user_id="alice")
m.add("Christopher Nolan was born in London in 1970.", user_id="alice")
m.relink(user_id="alice")  # batch linking pass — run after adding several

for r in m.search("Who directed Inception?", user_id="alice", limit=1):
    print(r.title, "-", r.via)

# Christopher Nolan directed Inception. - direct
# Christopher Nolan was born in London in 1970. - link   <- pulled in via the shared entity

No server, no API key, nothing to sign up for — it runs fully on your machine. Full reference: Embedded / Memory.

Connect an agent

Already have a Cortex account and want an agent to use it, rather than writing Python yourself?

API reference

Building against the REST API directly (what the web app and the Python client both use)? See the API reference.

On this page