The Perigon API suite provides fast, structured access to global news and events, helping you build real-time, data-driven products. Whether you’re tracking emerging risks, surfacing relevant articles, or uncovering key insights, Perigon gives you the tools to do it programmatically.Unlike traditional keyword-based search, Perigon’s semantic search capabilities allow it to understand queries contextually and return relevant documents.This notebook demonstrates how to use Perigon’s retrievers with LangChain for both news articles and Wikipedia content.
from langchain_perigon import ArticlesRetriever# Create a new instance of the ArticlesRetriever# PERIGON_API_KEY is automatically read from environment variablesretriever = ArticlesRetriever()try: # Search for articles using semantic search documents = retriever.invoke("artificial intelligence developments") # Check if we got results if not documents: print("No articles found for the given query.") else: print(f"Found {len(documents)} articles") # Display first 3 results with metadata for doc in documents[:3]: # Safely extract metadata with fallbacks print(f"Title: {doc.metadata.get('title', 'N/A')}") print(f"URL: {doc.metadata.get('url', 'N/A')}") print(f"Published: {doc.metadata.get('publishedAt', 'N/A')}") print(f"Content: {doc.page_content[:200]}...") print("-" * 80)except Exception as e: print(f"Error retrieving articles: {e}")
from langchain_perigon import WikipediaRetriever# Create a new instance of the WikipediaRetriever# PERIGON_API_KEY is automatically read from environment variableswiki_retriever = WikipediaRetriever()try: # Search for Wikipedia articles using semantic search documents = wiki_retriever.invoke("quantum computing") # Validate results before processing if not documents: print("No Wikipedia articles found for the given query.") else: print(f"Found {len(documents)} Wikipedia articles") # Display first 3 results with rich metadata for doc in documents[:3]: # Extract Wikipedia-specific metadata safely print(f"Title: {doc.metadata.get('title', 'N/A')}") print(f"Pageviews: {doc.metadata.get('pageviews', 'N/A')}") print(f"Wikidata ID: {doc.metadata.get('wikidataId', 'N/A')}") print(f"Content: {doc.page_content[:200]}...") print("-" * 80)except Exception as e: print(f"Error retrieving Wikipedia articles: {e}")