87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
import asyncio
|
||
from sqlalchemy.ext.asyncio import AsyncSession
|
||
from app.database import AsyncSessionLocal, engine
|
||
from app.models import Signal, ContextNode, Experiment
|
||
from sqlalchemy import text
|
||
import uuid
|
||
|
||
async def seed_data():
|
||
async with AsyncSessionLocal() as session:
|
||
# 1. Clear existing data (optional, but good for a clean start)
|
||
await session.execute(text("TRUNCATE TABLE signals, context_nodes, experiments RESTART IDENTITY CASCADE;"))
|
||
|
||
# 2. Seed Signals (外部信号 - 触发工作的源头)
|
||
signals = [
|
||
Signal(
|
||
source="HackerNews",
|
||
content="DeepSeek-V3 release: 671B parameters, beats GPT-4 on coding tasks.",
|
||
impact_score=0.95,
|
||
processed=False
|
||
),
|
||
Signal(
|
||
source="Internal User Feedback",
|
||
content="RAG retrieval is too slow (avg 3s), users are dropping off.",
|
||
impact_score=0.85,
|
||
processed=False
|
||
),
|
||
Signal(
|
||
source="Arxiv",
|
||
content="Paper: 'Lost in the Middle: How Language Models Use Long Contexts'",
|
||
impact_score=0.6,
|
||
processed=True
|
||
)
|
||
]
|
||
session.add_all(signals)
|
||
|
||
# 3. Seed Context Nodes (团队当前的认知/共识)
|
||
context_nodes = [
|
||
ContextNode(
|
||
content="当前 RAG 切片大小设定为 512 tokens,重叠 50 tokens。",
|
||
version=1,
|
||
status="active"
|
||
),
|
||
ContextNode(
|
||
content="所有 SQL 生成任务默认使用 gpt-4-turbo,因为其指令遵循能力最强。",
|
||
version=2,
|
||
status="active"
|
||
),
|
||
ContextNode(
|
||
content="向量数据库使用 pgvector,当前索引类型为 ivfflat。",
|
||
version=1,
|
||
status="active"
|
||
)
|
||
]
|
||
session.add_all(context_nodes)
|
||
|
||
# 4. Seed Experiments (基于信号和认知制定的行动)
|
||
experiments = [
|
||
Experiment(
|
||
title="评估 DeepSeek-V3 的 SQL 生成能力",
|
||
hypothesis="如果 DeepSeek-V3 在 Spider 数据集上表现达到 95% GPT-4 水平,我们可以替换 GPT-4 以降低 90% 成本。",
|
||
status="running",
|
||
target_metric="accuracy_vs_cost",
|
||
current_score=0.88
|
||
),
|
||
Experiment(
|
||
title="RAG 延迟优化:混合检索策略",
|
||
hypothesis="引入 BM25 稀疏检索 + 向量检索的混合模式,可以在保持召回率的同时减少重排序候选集,降低延迟。",
|
||
status="draft",
|
||
target_metric="latency_p95",
|
||
current_score=None
|
||
),
|
||
Experiment(
|
||
title="上下文窗口扩展测试",
|
||
hypothesis="将上下文窗口扩展到 128k,测试在大文档问答中的准确率变化。",
|
||
status="failed",
|
||
target_metric="recall",
|
||
current_score=0.45
|
||
)
|
||
]
|
||
session.add_all(experiments)
|
||
|
||
await session.commit()
|
||
print("Database seeded successfully with initial data!")
|
||
|
||
if __name__ == "__main__":
|
||
asyncio.run(seed_data())
|