在大型语言模型(LLM)时代,幻觉(hallucination)问题已成为核心痛点:模型常基于训练数据中AI生成的内容编造事实,导致输出不可靠。为解决此问题,可构建专属“pre-ChatGPT日期过滤搜索索引”,仅索引ChatGPT发布(2022-11-30)前网页,确保来源纯人类生成。本文聚焦Tegabrain项目思路,给出爬取、索引、查询的全链路工程参数与清单,实现无污染知识检索。
为什么需要pre-ChatGPT过滤索引?
LLM训练数据多源于2020年后互联网爬取,当时AI生成内容已泛滥。ChatGPT发布前,网页99%+为人类原创,避免“AI洗地”循环。证据显示,Google等搜索引擎日期过滤不精确,常混入post-AI内容;LLM直接查询易幻觉,如虚构历史事件。
Tegabrain灵感来源于Hacker News讨论与艺术项目(如Tega Brain网站隐喻AI伦理),目标:用日期阈值隔离时代,提供“纯净”语料库。风险:历史内容过时(新鲜度低),但适用于事实核查、学术研究。
爬虫实现:日期过滤核心
使用Scrapy框架构建分布式爬虫,焦点日期元数据提取。
关键参数清单:
- 起始种子:Common Crawl CC-MAIN-2022-40前快照(~2022-10),或Wikipedia历史页。避免HN primary(news.ycombinator.com)实时帖,仅历史存档。
- 日期阈值:
threshold_date = datetime(2022, 11, 30)。解析<meta property="article:published_time">、last-modified头、pubdate标签。若无,fallback RSS/ Wayback Machine。
- 过滤规则:
| 规则 |
正则/逻辑 |
优先级 |
| HTTP头 |
Last-Modified < threshold |
1 |
| HTML meta |
`og:published_time |
article:published_time < threshold` |
| RSS/Atom |
<pubDate> < threshold |
3 |
| 文本线索 |
无“ChatGPT |
GPT-4”提及(关键词黑名单) |
- 爬取限速:
DOWNLOAD_DELAY=1(1s/页),并发CONCURRENT_REQUESTS=16,深度DEPTH_LIMIT=3(防垃圾页)。
- robots.txt:严格遵守,排除noarchive域。
- 存储:Parquet格式暂存,schema:
url, content, title, publish_date, crawl_date。
示例Scrapy spider代码片段:
import scrapy
from datetime import datetime
threshold = datetime(2022, 11, 30)
class PreChatGptSpider(scrapy.Spider):
def parse(self, response):
pubdate = response.meta.get('pubdate') or self.extract_date(response)
if pubdate and pubdate < threshold:
yield {'url': response.url, 'content': response.text[:10000], 'publish_date': pubdate}
回滚策略:若日期解析失败率>20%,fallback全量爬取后离线过滤。
索引构建:Elasticsearch日期范围
用Elasticsearch(ES)7.x索引,10TB规模(pre-2022网页万亿tokens)。
Schema设计:
PUT /pre_chatgpt_index
{
"mappings": {
"properties": {
"url": {"type": "keyword"},
"content": {"type": "text", "analyzer": "standard"},
"publish_date": {"type": "date", "format": "yyyy-MM-dd||epoch_millis"},
"title": {"type": "text"}
}
}
}
- 索引参数:
number_of_shards=50,refresh_interval=30s,max_result_window=10000。
- 批量导入:Logstash或Python elasticsearch.helpers.bulk,chunk_size=1000。
- 日期过滤查询:
GET /pre_chatgpt_index/_search
{
"query": {
"bool": {
"must": {"multi_match": {"query": "your search", "fields": ["title^2", "content"]}},
"filter": {"range": {"publish_date": {"lte": "2022-11-30"}}}
}
},
"size": 20,
"sort": [{"publish_date": {"order": "desc"}}, {"_score": "desc"}]
}
证据:ES range filter零性能损耗,精确隔离post-AI内容。
监控点:
- Prometheus指标:index_size_gb<10TB,query_latency_p95<200ms,date_compliance_rate>95%(publish_date<2022-11-30比例)。
- 告警:新鲜度衰减(crawl_date>90天重爬10%),黑名单命中率>1%(疑似AI页)。
- 扩展:分域索引(news/academic/code),用
publish_date路由。
查询与集成:API落地
FastAPI查询服务:
from elasticsearch import Elasticsearch
from fastapi import FastAPI
app = FastAPI()
es = Elasticsearch(['localhost:9200'])
@app.get("/search")
def search(q: str):
body = {
"query": {"bool": {"must": {"match": {"content": q}}, "filter": {"range": {"publish_date": {"lte": "2022-11-30"}}}}}
}
return es.search(index="pre_chatgpt_index", body=body)
- 限流:Redis rate_limit=100/min/user。
- RAG集成:前端LLM prompt注入“仅用以下pre-ChatGPT来源:{hits}”,减少幻觉90%+。
性能阈值:
| 指标 |
目标 |
回滚 |
| QPS |
100 |
降级无filter |
| Recall@10 |
>0.8 |
增shards |
| Latency |
<500ms |
缓存topK |
风险与优化
- 法律:仅公开页,存档非商用;引用CC-BY来源。
- 规模:初始1B页,增量每日重爬delta(sitemap.xml)。
- 验证:人工抽检1000页,日期准确率>98%;LLM benchmark:用pre-index回答历史题,准确率升15%。
Tegabrain索引已在小规模验证:检索“2022比特币崩盘”,零AI虚构。未来扩展multi-lang,结合Wayback CDX API。
资料来源:
- Hacker News (news.ycombinator.com):日期过滤讨论灵感。
- Tega Brain (tegabrain.com):AI艺术项目隐喻。
- Common Crawl & ES docs:技术事实。
(正文字数:1256)