> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/ai/semantic-search/python.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Python

Query the knowledge base with **vector similarity** over HTTP.

## Basic search

```python
import asyncio
from dnotifier import DNotifier

USER_ID = "user-123"

async def main():
    notifier = DNotifier(
        app_id="your-app-id",
        secret="your-app-secret",
        transport="http",
        user_id=USER_ID,
    )

    await notifier.connect()

    hits = await notifier.search(
        sender_id=USER_ID,
        query="how long do refunds take",
        limit=5,
        min_similarity=0.7,
        filterby_source="help-center",
    )

    print(hits)

asyncio.run(main())
```

## Search then answer manually

```python
async def answer_with_search(notifier: DNotifier, user_question: str) -> str:
    hits = await notifier.search(
        sender_id=USER_ID,
        query=user_question,
        limit=3,
        min_similarity=0.5,
    )

    context = str(hits)

    response = await notifier.send_ai(
        sender_id=USER_ID,
        message={
            "messages": [
                {
                    "role": "system",
                    "content": f"Answer using only this context:\n{context}",
                },
                {"role": "user", "content": user_question},
            ],
        },
        save_history=True,
    )

    if isinstance(response, dict) and isinstance(response.get("data"), dict):
        return str(response["data"].get("content", ""))
    return str(response)
```

## Workflow context

```python
hits = await ctx.search(
    query="refund policy",
    limit=10,
    min_similarity=0.3,
    filterby_source="help-center",
    label="FAQ search",
)
```

## Learn more

* [**Manage documents**](https://dnotifier.gitbook.io/product-docs/ai/manage-documents/python.md)
* [**Example: RAG bot**](https://dnotifier.gitbook.io/product-docs/ai/example-rag-bot/python.md)
