Skip to navigation

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

import os
os.environ["YDC_API_KEY"] = "<YDC_API_KEY>"

Get your API key at you.com/platform.


Usage

Set up the retriever and retrieve web results:

import os
from llama_index.retrievers.you import YouRetriever
retriever = YouRetriever(api_key=os.environ["YDC_API_KEY"])
retrieved_results = retriever.retrieve("national parks in the US")
print(f"Retrieved {len(retrieved_results)} results")
for i, result in enumerate(retrieved_results):
print(f"\nResult {i+1}:")
print(f" Text: {result.node.text}...")
print("Metadata:")
for key, value in result.node.metadata.items():
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:

import os
from llama_index.retrievers.you import YouRetriever
retriever = YouRetriever(
api_key=os.environ["YDC_API_KEY"],
count=20, # Up to 20 results per section (web/news)
country="US", # Focus on US results
language="en", # English results
freshness="week", # Results from the past week
safesearch="moderate",
)
retrieved_results = retriever.retrieve("renewable energy breakthroughs")

Resources