> 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/examples/rag-assistant/python.md).

# Python

```python
import asyncio
import os
from dnotifier import DNotifier

SENDER = "support-agent"

ARTICLES = [
    {
        "record_id": "refund-policy",
        "content": "Refund requests are processed within 5 business days after approval.",
        "metadata": {"source": "help-center", "topic": "billing"},
    },
    {
        "record_id": "password-reset",
        "content": "Reset your password from Settings > Security > Send reset email.",
        "metadata": {"source": "help-center", "topic": "account"},
    },
]

async def main():
    notifier = DNotifier(
        app_id=os.environ["DNOTIFIER_APP_ID"],
        secret=os.environ["DNOTIFIER_SECRET"],
        transport="http",
        user_id=SENDER,
    )

    await notifier.connect()

    for doc in ARTICLES:
        await notifier.add_document(
            sender_id=SENDER,
            record_id=doc["record_id"],
            content=doc["content"],
            doc_type="text",
            metadata=doc["metadata"],
        )
        print(f"Indexed: {doc['record_id']}")

    question = "How long do refunds take?"

    hits = await notifier.search(
        sender_id=SENDER,
        query=question,
        limit=3,
        min_similarity=0.6,
        filterby_source="help-center",
    )
    print(f"Search hits: {hits}")

    answer = await notifier.send_ai(
        sender_id=SENDER,
        message={
            "useKnowledgeBase": True,
            "messages": [
                {"role": "system", "content": "Answer using only the knowledge base. Be concise."},
                {"role": "user", "content": question},
            ],
        },
        save_history=True,
    )
    print(f"RAG answer: {answer}")

asyncio.run(main())
```

## Get one document

```python
doc = await notifier.get_document(
    sender_id=SENDER,
    record_id="refund-policy",
)
```

## Delete when done

```python
await notifier.delete_document(
    sender_id=SENDER,
    record_id="refund-policy",
)
```
