Skip to main content
Dappier 将任何 LLM 或 AI 智能体与来自可信来源的实时、经授权、专有数据连接,使你的 AI 成为任何领域的专家。我们的专业模型包括实时网络搜索、新闻、体育、金融股市数据、加密数据以及来自优质出版商的专属内容。在我们的市场 marketplace.dappier.com 上探索各种数据模型。 Dappier 提供经过丰富处理、随时可用于提示且与上下文相关的数据字符串,优化了与 LangChain 的无缝集成。无论你是在构建对话式 AI、推荐引擎还是智能搜索,Dappier 的 LLM 无关 RAG 模型都确保你的 AI 能够访问经过验证的最新数据——无需构建和管理自己的检索流水线。

DappierRetriever

本指南将帮助你开始使用 Dappier 检索器。有关所有 DappierRetriever 功能和配置的详细文档,请参阅 API 参考

设置

安装 langchain-dappier 并设置环境变量 DAPPIER_API_KEY
pip install -U langchain-dappier
export DAPPIER_API_KEY="your-api-key"
我们还需要设置 Dappier API 凭据,可以在 Dappier 网站生成。 我们可以通过访问 Dappier 市场找到支持的数据模型。 如果你想要从各个查询中获取自动追踪,也可以通过取消以下注释来设置你的 LangSmith API 密钥:
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"

安装

此检索器位于 langchain-dappier 包中:
pip install -qU langchain-dappier

实例化

  • data_model_id: str 数据模型 ID,以 dm_ 开头。 可在以下位置找到可用的数据模型 ID: Dappier 市场
  • k: int 要返回的文档数量。
  • ref: Optional[str] 显示 AI 推荐的网站域名。
  • num_articles_ref: int 来自指定 ref 域名的文章最少数量。 其余文章将来自 RAG 模型内的其他网站。
  • search_algorithm: Literal[ “most_recent”, “most_recent_semantic”, “semantic”, “trending” ] 用于检索文章的搜索算法。
  • api_key: Optional[str] 用于与 Dappier API 交互的 API 密钥。
from langchain_dappier import DappierRetriever

retriever = DappierRetriever(data_model_id="dm_01jagy9nqaeer9hxx8z1sk1jx6")

使用方法

query = "latest tech news"

retriever.invoke(query)
[Document(metadata={'title': 'Man shot and killed on Wells Street near downtown Fort Wayne', 'author': 'Gregg Montgomery', 'source_url': 'https://www.wishtv.com/news/indiana-news/man-shot-dies-fort-wayne-december-25-2024/', 'image_url': 'https://images.dappier.com/dm_01jagy9nqaeer9hxx8z1sk1jx6/fort-wayne-police-department-vehicle-via-Flickr_.jpg?width=428&height=321', 'pubdata': 'Thu, 26 Dec 2024 01:00:33 +0000'}, page_content='A man was shot and killed on December 25, 2024, in Fort Wayne, Indiana, near West Fourth and Wells streets. Police arrived shortly after 6:30 p.m. following reports of gunfire and found the victim in the 1600 block of Wells Street, where he was pronounced dead. The area features a mix of businesses, including a daycare and restaurants.\n\nAs of the latest updates, police have not provided details on the safety of the area, potential suspects, or the motive for the shooting. Authorities are encouraging anyone with information to reach out to the Fort Wayne Police Department or Crime Stoppers.'),
 Document(metadata={'title': 'House cat dies from bird flu in pet food, prompting recall', 'author': 'Associated Press', 'source_url': 'https://www.wishtv.com/news/business/house-cat-bird-flu-pet-food-recall/', 'image_url': 'https://images.dappier.com/dm_01jagy9nqaeer9hxx8z1sk1jx6/BACKGROUND-Northwest-Naturals-cat-food_.jpg?width=428&height=321', 'pubdata': 'Wed, 25 Dec 2024 23:12:41 +0000'}, page_content='An Oregon house cat has died after eating pet food contaminated with the H5N1 bird flu virus, prompting a nationwide recall of Northwest Naturals\' 2-pound Feline Turkey Recipe raw frozen pet food. The Oregon Department of Agriculture confirmed that the strictly indoor cat contracted the virus solely from the food, which has "best if used by" dates of May 21, 2026, and June 23, 2026. \n\nThe affected product was distributed across several states, including Arizona, California, and Florida, as well as British Columbia, Canada. Consumers are urged to dispose of the recalled food and seek refunds. This incident raises concerns about the spread of bird flu and its potential impact on domestic animals, particularly as California has declared a state of emergency due to the outbreak affecting various bird species.'),
 Document(metadata={'title': '20 big cats die from bird flu at Washington sanctuary', 'author': 'Nic F. Anderson, CNN', 'source_url': 'https://www.wishtv.com/news/national/bird-flu-outbreak-wild-felid-center-2024/', 'image_url': 'https://images.dappier.com/dm_01jagy9nqaeer9hxx8z1sk1jx6/BACKGROUND-Amur-Bengal-tiger-at-Wild-Felid-Advocacy-Center-of-Washington-FB-post_.jpg?width=428&height=321', 'pubdata': 'Wed, 25 Dec 2024 23:04:34 +0000'}, page_content='The Wild Felid Advocacy Center in Washington state has experienced a devastating bird flu outbreak, resulting in the deaths of 20 big cats, over half of its population. The first death was reported around Thanksgiving, affecting various species, including cougars and a tiger mix. The sanctuary is currently under quarantine, closed to the public, and working with animal health officials to disinfect enclosures and implement prevention strategies.\n\nAs the situation unfolds, the Washington Department of Fish and Wildlife has noted an increase in bird flu cases statewide, including infections in cougars. While human infections from bird flu through contact with mammals are rare, the CDC acknowledges the potential risk. The sanctuary hopes to reopen in the new year, focusing on the recovery of the remaining animals and taking measures to prevent further outbreaks, marking an unprecedented challenge in its 20-year history.')]

API 参考

有关所有 DappierRetriever 功能和配置的详细文档,请参阅 API 参考