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

# Quickstart

> Install Cognis and run your first memory operations in 3 minutes.

## 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

<Tabs>
  <Tab title="Hosted (lyzr-adk)">
    ```bash theme={null}
    pip install lyzr-adk
    ```
  </Tab>

  <Tab title="Open Source (lyzr-cognis)">
    ```bash theme={null}
    pip install lyzr-cognis
    ```
  </Tab>
</Tabs>

## 2. Set API keys

<Tabs>
  <Tab title="Hosted (lyzr-adk)">
    ```bash theme={null}
    export LYZR_API_KEY="your-lyzr-api-key"
    ```
  </Tab>

  <Tab title="Open Source (lyzr-cognis)">
    ```bash theme={null}
    export GEMINI_API_KEY="your-gemini-key"
    export OPENAI_API_KEY="your-openai-key"
    ```
  </Tab>
</Tabs>

## 3. Add memories

Send conversation messages to Cognis. It extracts and stores discrete facts automatically.

<Tabs>
  <Tab title="Hosted (lyzr-adk)">
    ```python theme={null}
    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",
    )
    ```
  </Tab>

  <Tab title="Open Source (lyzr-cognis)">
    ```python theme={null}
    from cognis import Cognis

    m = Cognis(owner_id="user_alice")

    result = m.add([
        {"role": "user", "content": "My name is Alice. I love hiking and I'm vegetarian."},
        {"role": "assistant", "content": "Nice to meet you, Alice!"},
    ])
    print(result["message"])
    # "Extracted 3 memories from 2 messages"
    ```
  </Tab>
</Tabs>

## 4. Search memories

Retrieve the most relevant facts before your agent responds.

<Tabs>
  <Tab title="Hosted (lyzr-adk)">
    ```python theme={null}
    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)"
    ```
  </Tab>

  <Tab title="Open Source (lyzr-cognis)">
    ```python theme={null}
    resp = m.search("What does Alice eat?", limit=5)
    for r in resp["results"]:
        print(f"{r['content']}  (score: {r['score']})")
    # "Alice is vegetarian  (score: 0.8712)"
    ```
  </Tab>
</Tabs>

## 5. Get context for your LLM

Assemble both short-term conversation history and long-term memories into a single string for your system prompt.

<Tabs>
  <Tab title="Hosted (lyzr-adk)">
    ```python theme={null}
    context = cog.context(
        current_messages=[CognisMessage(role="user", content="Recommend a restaurant")],
        owner_id="user_alice",
    )
    # Pass context into your LLM system prompt
    ```
  </Tab>

  <Tab title="Open Source (lyzr-cognis)">
    ```python theme={null}
    ctx = m.get_context(
        messages=[{"role": "user", "content": "Recommend a restaurant"}]
    )
    print(ctx["context_string"])
    # "Relevant memories:\n- Alice is vegetarian\n- ..."

    m.close()  # Required for the OSS client
    ```
  </Tab>
</Tabs>

## 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

* [Memory types](./memory-types): understand session, long-term, and cross-session scoping.
* [Add Memories reference](./api/add-memories): full parameter and response documentation.
* [Search Memories reference](./api/search-memories): scoring, filtering, and limit options.
