#![allow(
clippy::unwrap_used,
clippy::expect_used,
reason = "integration test code — panics are acceptable"
)]
use cognee_models::{DataPoint, DocumentChunk};
use cognee_test_utils::MockVectorDB;
use cognee_vector::{VectorDB, VectorPoint};
use uuid::Uuid;
#[tokio::test]
async fn vector_point_carries_full_datapoint_dump() {
let document_id = Uuid::new_v4();
let mut chunk = DocumentChunk::new(
Uuid::new_v4(),
"hello".into(),
1,
0,
"paragraph_end".into(),
document_id,
);
chunk.base.source_pipeline = Some("cognify_pipeline".into());
chunk.base.source_task = Some("extract_chunks_from_documents".into());
chunk.base.source_user = Some("alice@example.com".into());
chunk.base.source_node_set = Some("text_nodes".into());
chunk.base.source_content_hash = Some("md5:abcdef".into());
let mut point = VectorPoint::new(chunk.base.id, vec![0.0; 384]);
for (k, v) in chunk.base.vector_metadata() {
point = point.with_metadata(k, v);
}
let db = MockVectorDB::new();
db.create_collection("DocumentChunk", "text", 384)
.await
.unwrap();
db.index_points("DocumentChunk", "text", &[point])
.await
.unwrap();
let stored = db
.get_payload("DocumentChunk", "text", chunk.base.id)
.expect("indexed point must round-trip through MockVectorDB");
assert_eq!(
stored.get("source_pipeline").and_then(|v| v.as_str()),
Some("cognify_pipeline")
);
assert_eq!(
stored.get("source_task").and_then(|v| v.as_str()),
Some("extract_chunks_from_documents")
);
assert_eq!(
stored.get("source_user").and_then(|v| v.as_str()),
Some("alice@example.com")
);
assert_eq!(
stored.get("source_node_set").and_then(|v| v.as_str()),
Some("text_nodes")
);
assert_eq!(
stored.get("source_content_hash").and_then(|v| v.as_str()),
Some("md5:abcdef")
);
assert_eq!(
stored.get("type").and_then(|v| v.as_str()),
Some("DocumentChunk"),
"DataPoint::vector_metadata() must preserve the `type` rename"
);
}
#[tokio::test]
async fn omitted_provenance_fields_are_absent_from_payload() {
let dp = DataPoint::new("Entity", None);
let mut point = VectorPoint::new(dp.id, vec![0.0; 4]);
for (k, v) in dp.vector_metadata() {
point = point.with_metadata(k, v);
}
let db = MockVectorDB::new();
db.create_collection("Entity", "name", 4).await.unwrap();
db.index_points("Entity", "name", &[point]).await.unwrap();
let stored = db
.get_payload("Entity", "name", dp.id)
.expect("indexed point round-trip");
for absent in [
"source_pipeline",
"source_task",
"source_user",
"source_node_set",
"source_content_hash",
] {
assert!(
!stored.contains_key(absent),
"expected {absent} to be omitted from payload when the DataPoint field is None"
);
}
}