Hotdry.
application-security

Tegabrain:构建ChatGPT发布前日期过滤搜索索引

通过日期过滤爬虫抓取并索引2022-11-30前网页内容,避免LLM幻觉污染,提供纯人类生成来源的可靠搜索。

在大型语言模型(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}
        # 递归follow links, max depth 3

回滚策略:若日期解析失败率 > 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=50refresh_interval=30smax_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)

查看归档