Skip to main content

Prerequisites

  • Python 3.8 or later.
  • A Lyzr API key for the hosted version, or API keys for Gemini (embeddings) and OpenAI (fact extraction) for the open-source version.

1. Install

pip install lyzr-adk

2. Set API keys

export LYZR_API_KEY="your-lyzr-api-key"

3. Add memories

Send conversation messages to Cognis. It extracts and stores discrete facts automatically.
from lyzr import Cognis, CognisMessage

cog = Cognis(api_key="sk-your-api-key")

cog.add(
    messages=[
        CognisMessage(role="user", content="My name is Alice. I love hiking and I'm vegetarian."),
        CognisMessage(role="assistant", content="Nice to meet you, Alice!"),
    ],
    owner_id="user_alice",
)

4. Search memories

Retrieve the most relevant facts before your agent responds.
results = cog.search(query="What does Alice eat?", owner_id="user_alice", limit=5)
for r in results:
    print(f"{r.content}  (score: {r.score})")
# "Alice is vegetarian  (score: 0.89)"

5. Get context for your LLM

Assemble both short-term conversation history and long-term memories into a single string for your system prompt.
context = cog.context(
    current_messages=[CognisMessage(role="user", content="Recommend a restaurant")],
    owner_id="user_alice",
)
# Pass context into your LLM system prompt

What just happened

Cognis stored your raw messages, then the extraction layer pulled discrete facts and auto-categorized them (identity, preferences, interests, and more). Each fact was embedded and indexed for hybrid search using 70% vector similarity and 30% BM25 keyword matching. The context / get_context call assembled both short-term messages and long-term memories into a ready-to-use LLM context string.

Next steps