|
| 1 | +--- |
| 2 | +title: Perigon |
| 3 | +--- |
| 4 | + |
| 5 | +>[Perigon](https://perigon.io/) is a comprehensive news API that provides access to real-time contextual information in news articles, stories, metadata and wikipedia pages from thousands of sources worldwide. |
| 6 | +> |
| 7 | +
|
| 8 | +## Installation and Setup |
| 9 | + |
| 10 | +`Perigon` integration exists in its own [partner package](https://pypi.org/project/langchain-perigon/). You can install it with: |
| 11 | + |
| 12 | +```python |
| 13 | +%pip install -qU langchain-perigon |
| 14 | +``` |
| 15 | + |
| 16 | +In order to use the package, you will also need to set the `PERIGON_API_KEY` environment variable to your Perigon API key. |
| 17 | + |
| 18 | +## Retrievers |
| 19 | + |
| 20 | +Perigon provides two retrievers: |
| 21 | + |
| 22 | +### ArticlesRetriever |
| 23 | + |
| 24 | +This retriever retrieves articles based on a given query and optional filters. |
| 25 | + |
| 26 | +See a [full usage example](/oss/integrations/retrievers/perigon#using-articlesretriever). |
| 27 | + |
| 28 | +```python |
| 29 | +# Make sure PERIGON_API_KEY environment variable is set to your Perigon API key |
| 30 | +from langchain_perigon import ArticlesRetriever, ArticlesFilter |
| 31 | + |
| 32 | +# Create retriever with specific number of results |
| 33 | +retriever = ArticlesRetriever(k=12) |
| 34 | + |
| 35 | +# Configure filter options to exclude reprints and focus on US articles |
| 36 | +options: ArticlesFilter = { |
| 37 | + "showReprints": False, # Exclude duplicate/reprint articles |
| 38 | + "filter": {"country": "us"}, # Only US-based news |
| 39 | +} |
| 40 | + |
| 41 | +try: |
| 42 | + documents = retriever.invoke("Recent big tech layoffs", options=options) |
| 43 | + |
| 44 | + # Check if we got results before accessing |
| 45 | + if documents: |
| 46 | + print(f"First document: {documents[0].page_content[:200]}...") |
| 47 | + else: |
| 48 | + print("No articles found for the given query.") |
| 49 | +except Exception as e: |
| 50 | + print(f"Error retrieving articles: {e}") |
| 51 | +``` |
| 52 | + |
| 53 | +You can use the `ArticlesRetriever` in a standard retrieval pipeline: |
| 54 | + |
| 55 | +### WikipediaRetriever |
| 56 | + |
| 57 | +This retriever retrieves wikipedia pages based on a given query and optional filters. |
| 58 | + |
| 59 | +See a [full usage example](/oss/integrations/retrievers/perigon#using-wikipediaretriever). |
| 60 | + |
| 61 | +```python |
| 62 | +# Make sure PERIGON_API_KEY environment variable is set to your Perigon API key |
| 63 | +from langchain_perigon import WikipediaRetriever |
| 64 | + |
| 65 | +# Create retriever with specific number of results |
| 66 | +retriever = WikipediaRetriever(k=12) |
| 67 | + |
| 68 | +try: |
| 69 | + documents = retriever.invoke("machine learning") |
| 70 | + |
| 71 | + # Safely access results with error handling |
| 72 | + if documents: |
| 73 | + print(f"First document: {documents[0].page_content[:200]}...") |
| 74 | + else: |
| 75 | + print("No Wikipedia articles found for the given query.") |
| 76 | +except Exception as e: |
| 77 | + print(f"Error retrieving Wikipedia articles: {e}") |
| 78 | +``` |
| 79 | + |
| 80 | +You can use the `WikipediaRetriever` in a standard retrieval pipeline: |
0 commit comments