跳转到内容

Notion 阅读器

演示我们的Notion数据连接器

%pip install llama-index-readers-notion
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

如果您在 Colab 上打开这个笔记本,您可能需要安装 LlamaIndex 🦙。

!pip install llama-index
from llama_index.core import SummaryIndex
from llama_index.readers.notion import NotionPageReader
from IPython.display import Markdown, display
import os
integration_token = os.getenv("NOTION_INTEGRATION_TOKEN")
page_ids = ["<page_id>"]
documents = NotionPageReader(integration_token=integration_token).load_data(
page_ids=page_ids
)
index = SummaryIndex.from_documents(documents)
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
display(Markdown(f"<b>{response}</b>"))

你也可以传入数据库的ID来索引该数据库中的所有页面:

database_ids = ["<database-id>"]
# https://developers.notion.com/docs/working-with-databases for how to find your database id
documents = NotionPageReader(integration_token=integration_token).load_data(
database_ids=database_ids
)
print(documents)
# set Logging to DEBUG for more detailed outputs
index = SummaryIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
display(Markdown(f"<b>{response}</b>"))

要列出您的Notion工作区中的所有数据库:

reader = NotionPageReader(integration_token=integration_token)
databases = reader.list_databases()
print(databases)