Google I/O 2026 通过 AI 模式(覆盖 1B+ 用户)、Gemini 3.5 Flash 和重新设计的搜索框改变了搜索结果的结构方式。搜索数据中响应的 RAG 管道需要适应这些变化。本教程更新了您的 RAG 基础,以处理新的结果格式、AI 概述引用和信息代理响应。
前置条件
- Python 3.8+
- 请求库
- 来自 scavio.dev 的 Scavio API 密钥
- 现有的 RAG 管道需要更新
操作指南
步骤 1: 检测新的搜索结果格式
确定您的查询返回哪些新的 I/O 后结果类型。
Python
import os, requests, json
from datetime import datetime
API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
def detect_result_format(query):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': query, 'country_code': 'us'}, timeout=10).json()
format_info = {
'query': query,
'has_ai_overview': bool(data.get('ai_overview', data.get('answer_box'))),
'has_featured_snippet': bool(data.get('featured_snippet')),
'has_knowledge_graph': bool(data.get('knowledge_graph')),
'has_paa': len(data.get('people_also_ask', [])) > 0,
'paa_count': len(data.get('people_also_ask', [])),
'organic_count': len(data.get('organic_results', [])),
'ai_overview_data': data.get('ai_overview', data.get('answer_box', {})),
}
return format_info, data
TEST_QUERIES = [
'what is model context protocol',
'best search api for ai agents 2026',
'how to build rag pipeline python',
]
print('Post-I/O 2026 Result Format Detection:\n')
for q in TEST_QUERIES:
fmt, _ = detect_result_format(q)
ai = 'AI' if fmt['has_ai_overview'] else '--'
fs = 'FS' if fmt['has_featured_snippet'] else '--'
kg = 'KG' if fmt['has_knowledge_graph'] else '--'
print(f' {q[:40]:40} | {ai} {fs} {kg} | PAA: {fmt["paa_count"]} | Org: {fmt["organic_count"]}')
print(f'\nCost: ${len(TEST_QUERIES) * 0.005:.3f}')步骤 2: 构建自适应接地提取
提取适用于新旧结果格式的基础数据。
Python
def extract_grounding(query):
"""Extract grounding data adaptive to post-I/O 2026 result formats."""
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': query, 'country_code': 'us'}, timeout=10).json()
grounding = {
'query': query,
'sources': [],
'direct_answer': '',
'related_questions': [],
'confidence': 'low',
}
# Priority 1: AI Overview (post-I/O, most authoritative)
ai = data.get('ai_overview', data.get('answer_box', {}))
if ai:
answer = ai.get('snippet', ai.get('answer', ai.get('description', '')))
if answer:
grounding['direct_answer'] = answer[:500]
grounding['confidence'] = 'high'
# Priority 2: Featured Snippet
featured = data.get('featured_snippet', {})
if not grounding['direct_answer'] and featured:
grounding['direct_answer'] = featured.get('snippet', '')[:500]
grounding['confidence'] = 'medium'
# Priority 3: Organic results (always available)
for r in data.get('organic_results', [])[:5]:
grounding['sources'].append({
'title': r.get('title', ''),
'url': r.get('link', ''),
'text': r.get('snippet', ''),
'domain': r.get('displayed_link', '').split('/')[0],
})
if not grounding['direct_answer'] and grounding['sources']:
grounding['direct_answer'] = grounding['sources'][0]['text']
grounding['confidence'] = 'low'
# Related questions for follow-up
grounding['related_questions'] = [q.get('question', '') for q in data.get('people_also_ask', [])[:3]]
return grounding
print('\n=== Adaptive Grounding Extraction ===')
for q in TEST_QUERIES:
g = extract_grounding(q)
print(f'\n Query: {q[:40]}')
print(f' Confidence: {g["confidence"]}')
print(f' Answer: {g["direct_answer"][:80]}...' if g['direct_answer'] else ' No direct answer')
print(f' Sources: {len(g["sources"])} | Related Qs: {len(g["related_questions"])}')步骤 3: 与 RAG 管道集成
用自适应提取器替换现有的搜索基础。
Python
def grounded_rag_response(question):
"""Generate a grounded response using adaptive post-I/O search data."""
print(f'\n Question: {question}')
# Step 1: Get grounding data
grounding = extract_grounding(question)
print(f' Grounding confidence: {grounding["confidence"]}')
print(f' Sources: {len(grounding["sources"])}')
# Step 2: Build context for LLM
context_parts = []
if grounding['direct_answer']:
context_parts.append(f'Direct answer: {grounding["direct_answer"]}')
for s in grounding['sources'][:3]:
context_parts.append(f'Source ({s["domain"]}): {s["text"]}')
context = '\n'.join(context_parts)
# Step 3: Format response with citations
print(f'\n Grounded Context ({len(context)} chars):')
for s in grounding['sources'][:3]:
print(f' [{s["domain"]:20}] {s["title"][:45]}')
# Step 4: Follow-up grounding
if grounding['related_questions']:
print(f'\n Available follow-ups:')
for q in grounding['related_questions']:
print(f' - {q[:55]}')
return {
'context': context,
'sources': grounding['sources'],
'confidence': grounding['confidence'],
}
print('=== Post-I/O 2026 Grounded RAG ===')
for q in ['what is MCP protocol', 'best search api for rag 2026']:
grounded_rag_response(q)
print(f'\n Grounding cost: $0.005/query')
print(f' Adapts to AI Mode, Featured Snippets, and organic results')
print(f' Works with Gemini 3.5 Flash and new search box format')Python 示例
Python
import os, requests
SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}
def ground(query):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': query, 'country_code': 'us'}, timeout=10).json()
ai = data.get('ai_overview', data.get('answer_box', {}))
answer = ai.get('snippet', '') if ai else data.get('organic_results', [{}])[0].get('snippet', '')
sources = [r.get('link', '') for r in data.get('organic_results', [])[:3]]
print(f'Answer: {answer[:80]}')
print(f'Sources: {len(sources)}')
ground('what is MCP protocol')JavaScript 示例
JavaScript
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
const data = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: SH,
body: JSON.stringify({ query: 'what is MCP protocol', country_code: 'us' })
}).then(r => r.json());
const ai = data.ai_overview || data.answer_box || {};
const answer = ai.snippet || (data.organic_results?.[0]?.snippet || '');
console.log(`Grounded answer: ${answer.slice(0, 80)}`);
console.log(`Sources: ${(data.organic_results || []).length}`);预期输出
JSON
Post-I/O 2026 Result Format Detection:
what is model context protocol | AI FS -- | PAA: 4 | Org: 10
best search api for ai agents 2026 | AI -- -- | PAA: 3 | Org: 10
how to build rag pipeline python | -- FS -- | PAA: 4 | Org: 10
=== Adaptive Grounding Extraction ===
Query: what is model context protocol
Confidence: high
Answer: Model Context Protocol (MCP) is an open standard for connecting...
Sources: 5 | Related Qs: 3
=== Post-I/O 2026 Grounded RAG ===
Question: what is MCP protocol
Grounding confidence: high
Sources: 5
Grounding cost: $0.005/query
Adapts to AI Mode, Featured Snippets, and organic results