LlamaIndex

View as Markdown

LlamaIndex includes a You.com retriever integration through the llama-index-retrievers-you package. It uses You.com’s 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

Install the package

$pip install llama-index-retrievers-you

Set your API key

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

Get your API key at you.com/platform/api-keys.


Basic Usage

Set up the retriever and retrieve web results:

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

Async Usage

The retriever also supports async operations:

1retrieved_results = await retriever.aretrieve("national parks in the US")

News Results

The Search API automatically includes news results based on your query. You can control how many results are returned per type and filter by country:

1retriever = YouRetriever(api_key="your_api_key", count=5, country="US")
2
3retrieved_results = retriever.retrieve("latest geopolitical updates")
4
5for result in retrieved_results:
6 print(result.node.metadata.get("source_type")) # "web" or "news"

Customizing Search Parameters

You can pass optional parameters to control the search behavior:

1retriever = YouRetriever(
2 api_key="your_api_key",
3 count=20, # Up to 20 results per section (web/news)
4 country="US", # Focus on US results
5 language="en", # English results
6 freshness="week", # Results from the past week
7 safesearch="moderate",
8)
9
10retrieved_results = retriever.retrieve("renewable energy breakthroughs")

Using with a Query Engine

Combine the retriever with an LLM to synthesize natural language answers from search results:

1from llama_index.core.query_engine import RetrieverQueryEngine
2from llama_index.llms.anthropic import Anthropic
3from llama_index.retrievers.you import YouRetriever
4
5llm = Anthropic(model="claude-haiku-4-5-20251001", api_key="your_anthropic_key")
6
7retriever = YouRetriever(api_key="your_api_key")
8query_engine = RetrieverQueryEngine.from_args(retriever, llm)
9
10response = query_engine.query(
11 "What are the most visited national parks in the US and why?"
12)
13print(str(response))

The query engine retrieves relevant search results from You.com, passes them as context to the LLM, and returns a synthesized answer.


Resources