Skip to content

"Vibe-Trading: Your Personal Trading Agent"

perf(research): index revision fingerprint lookups

Yufeng Hee95e9b79a0c4
diff --git a/agent/src/research_artifacts/store.py b/agent/src/research_artifacts/store.py
index a3574606e..7428424aa 100644
--- a/agent/src/research_artifacts/store.py
+++ b/agent/src/research_artifacts/store.py
@@ -108,6 +108,8 @@ class ResearchArtifactStore:
REFERENCES research_artifact_revisions(revision_id)
);
+ CREATE INDEX IF NOT EXISTS idx_research_artifact_fingerprint
+ ON research_artifact_revisions(content_hash, provenance_hash, artifact_id);
CREATE INDEX IF NOT EXISTS idx_research_artifact_series
ON research_artifact_revisions(artifact_id, revision_number);
CREATE INDEX IF NOT EXISTS idx_research_artifact_subject
diff --git a/agent/tests/test_research_artifact_store.py b/agent/tests/test_research_artifact_store.py
index b2f1d3491..0a23ff18d 100644
--- a/agent/tests/test_research_artifact_store.py
+++ b/agent/tests/test_research_artifact_store.py
@@ -203,6 +203,19 @@ def test_concurrent_instances_append_a_single_serial_revision_chain(
store.close()
+def test_fingerprint_lookup_uses_the_composite_index(tmp_path):
+ store = ResearchArtifactStore(tmp_path / "research.db")
+ rows = store._conn.execute(
+ "EXPLAIN QUERY PLAN SELECT * FROM research_artifact_revisions "
+ "WHERE content_hash = ? AND provenance_hash = ?",
+ ("missing-content", "missing-provenance"),
+ ).fetchall()
+ store.close()
+
+ plan = "\n".join(row["detail"] for row in rows)
+ assert "USING INDEX idx_research_artifact_fingerprint" in plan, plan
+
+
def test_nonfinite_evidence_is_rejected_before_persistence(tmp_path):
store = ResearchArtifactStore(tmp_path / "research.db")
with pytest.raises(ValueError):