LlamaIndex

View as MarkdownOpen in Claude

LlamaIndex includes a You.com retriever integration through the llama-index-retrievers-you package. It uses You.com’s Web Search API to retrieve relevant web and news results, converting them into LlamaIndex’s standard NodeWithScore format for use with query engines, agents, and other components.

Run this entire example as a Jupyter Notebook.

Getting Started

1

Install the Package

$pip install llama-index-retrievers-you
2

Set Your API Key

1import os
2
3os.environ["YDC_API_KEY"] = "<YDC_API_KEY>"

Get your API key at you.com/platform.


Usage

Set up the retriever and retrieve web results:

1import os
2from llama_index.retrievers.you import YouRetriever
3
4retriever = YouRetriever(api_key=os.environ["YDC_API_KEY"])
5retrieved_results = retriever.retrieve("national parks in the US")
6
7print(f"Retrieved {len(retrieved_results)} results")
8
9for i, result in enumerate(retrieved_results):
10 print(f"\nResult {i+1}:")
11 print(f" Text: {result.node.text}...")
12 print("Metadata:")
13 for key, value in result.node.metadata.items():
14 print(f" {key}: {value}")

Each result includes the page text along with metadata such as url, title, description, page_age, thumbnail_url, and source_type (either "web" or "news").

Customizing Search Parameters

You can pass optional parameters to control the search behavior:

1import os
2from llama_index.retrievers.you import YouRetriever
3
4retriever = YouRetriever(
5 api_key=os.environ["YDC_API_KEY"],
6 count=20, # Up to 20 results per section (web/news)
7 country="US", # Focus on US results
8 language="en", # English results
9 freshness="week", # Results from the past week
10 safesearch="moderate",
11)
12
13retrieved_results = retriever.retrieve("renewable energy breakthroughs")

Resources