1use std::collections::HashMap;
7use std::sync::Arc;
8
9use reddb_types::Value;
10
11pub const FIRST_USER_ENTITY_ID: u64 = 1024;
23
24pub use super::entity_id::EntityId;
25
26#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28pub enum EntityKind {
29 TableRow { table: Arc<str>, row_id: u64 },
31 GraphNode(Box<GraphNodeKind>),
33 GraphEdge(Box<GraphEdgeKind>),
35 Vector { collection: String },
37 TimeSeriesPoint(Box<TimeSeriesPointKind>),
39 QueueMessage { queue: String, position: u64 },
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, Hash)]
44pub struct GraphNodeKind {
45 pub label: String,
46 pub node_type: String,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub struct GraphEdgeKind {
51 pub label: String,
52 pub from_node: String,
53 pub to_node: String,
54 pub weight: u32,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, Hash)]
58pub struct TimeSeriesPointKind {
59 pub series: String,
60 pub metric: String,
61}
62
63impl EntityKind {
64 pub fn storage_type(&self) -> &'static str {
66 match self {
67 Self::TableRow { .. } => "table",
68 Self::GraphNode(_) => "graph_node",
69 Self::GraphEdge(_) => "graph_edge",
70 Self::Vector { .. } => "vector",
71 Self::TimeSeriesPoint(_) => "timeseries",
72 Self::QueueMessage { .. } => "queue",
73 }
74 }
75
76 pub fn collection(&self) -> &str {
78 match self {
79 Self::TableRow { table, .. } => table,
80 Self::GraphNode(n) => &n.label,
81 Self::GraphEdge(e) => &e.label,
82 Self::Vector { collection } => collection,
83 Self::TimeSeriesPoint(ts) => &ts.series,
84 Self::QueueMessage { queue, .. } => queue,
85 }
86 }
87}
88
89#[derive(Debug, Clone)]
91pub enum EntityData {
92 Row(RowData),
94 Node(NodeData),
96 Edge(EdgeData),
98 Vector(VectorData),
100 TimeSeries(TimeSeriesData),
102 QueueMessage(QueueMessageData),
104}
105
106impl EntityData {
107 pub fn is_row(&self) -> bool {
109 matches!(self, Self::Row(_))
110 }
111
112 pub fn is_node(&self) -> bool {
114 matches!(self, Self::Node(_))
115 }
116
117 pub fn is_edge(&self) -> bool {
119 matches!(self, Self::Edge(_))
120 }
121
122 pub fn is_vector(&self) -> bool {
124 matches!(self, Self::Vector(_))
125 }
126
127 pub fn as_row(&self) -> Option<&RowData> {
129 match self {
130 Self::Row(r) => Some(r),
131 _ => None,
132 }
133 }
134
135 pub fn as_node(&self) -> Option<&NodeData> {
137 match self {
138 Self::Node(n) => Some(n),
139 _ => None,
140 }
141 }
142
143 pub fn as_edge(&self) -> Option<&EdgeData> {
145 match self {
146 Self::Edge(e) => Some(e),
147 _ => None,
148 }
149 }
150
151 pub fn as_vector(&self) -> Option<&VectorData> {
153 match self {
154 Self::Vector(v) => Some(v),
155 _ => None,
156 }
157 }
158}
159
160#[derive(Debug, Clone)]
162pub struct RowData {
163 pub columns: Vec<Value>,
165 pub named: Option<HashMap<String, Value>>,
167 pub schema: Option<std::sync::Arc<Vec<String>>>,
171}
172
173impl RowData {
174 pub fn new(columns: Vec<Value>) -> Self {
176 Self {
177 columns,
178 named: None,
179 schema: None,
180 }
181 }
182
183 pub fn with_names(columns: Vec<Value>, names: Vec<String>) -> Self {
185 let named: HashMap<String, Value> =
186 names.into_iter().zip(columns.iter().cloned()).collect();
187 Self {
188 columns,
189 named: Some(named),
190 schema: None,
191 }
192 }
193
194 pub(crate) fn compact_with_schema(&mut self, schema: &std::sync::Arc<Vec<String>>) -> bool {
197 let Some(named) = &self.named else {
198 return false;
199 };
200 if named.len() != schema.len() || schema.iter().any(|name| !named.contains_key(name)) {
201 return false;
202 }
203 if !self.columns.is_empty()
206 && (self.columns.len() != schema.len()
207 || schema
208 .iter()
209 .zip(&self.columns)
210 .any(|(name, value)| named.get(name) != Some(value)))
211 {
212 return false;
213 }
214 let mut named = self.named.take().expect("validated named row");
215 self.columns = schema
216 .iter()
217 .map(|name| named.remove(name).expect("validated schema field"))
218 .collect();
219 self.schema = Some(std::sync::Arc::clone(schema));
220 true
221 }
222
223 pub fn get_field(&self, name: &str) -> Option<&Value> {
225 if let Some(ref named) = self.named {
227 return named.get(name);
228 }
229 if let Some(ref schema) = self.schema {
231 if let Some(idx) = schema.iter().position(|s| s == name) {
232 return self.columns.get(idx);
233 }
234 }
235 None
236 }
237
238 pub fn iter_fields(&self) -> Box<dyn Iterator<Item = (&str, &Value)> + '_> {
240 if let Some(ref named) = self.named {
241 Box::new(named.iter().map(|(k, v)| (k.as_str(), v)))
242 } else if let Some(ref schema) = self.schema {
243 Box::new(
244 schema
245 .iter()
246 .zip(self.columns.iter())
247 .map(|(k, v)| (k.as_str(), v)),
248 )
249 } else {
250 Box::new(std::iter::empty())
251 }
252 }
253
254 pub fn get(&self, index: usize) -> Option<&Value> {
256 self.columns.get(index)
257 }
258
259 pub fn get_by_name(&self, name: &str) -> Option<&Value> {
261 self.named.as_ref()?.get(name)
262 }
263
264 pub fn len(&self) -> usize {
266 self.columns.len()
267 }
268
269 pub fn is_empty(&self) -> bool {
271 self.columns.is_empty()
272 }
273}
274
275#[derive(Debug, Clone)]
277pub struct NodeData {
278 pub properties: HashMap<String, Value>,
280}
281
282impl NodeData {
283 pub fn new() -> Self {
285 Self {
286 properties: HashMap::new(),
287 }
288 }
289
290 pub fn with_properties(properties: HashMap<String, Value>) -> Self {
292 Self { properties }
293 }
294
295 pub fn set(&mut self, key: impl Into<String>, value: Value) {
297 self.properties.insert(key.into(), value);
298 }
299
300 pub fn get(&self, key: &str) -> Option<&Value> {
302 self.properties.get(key)
303 }
304
305 pub fn has(&self, key: &str) -> bool {
307 self.properties.contains_key(key)
308 }
309}
310
311impl Default for NodeData {
312 fn default() -> Self {
313 Self::new()
314 }
315}
316
317#[derive(Debug, Clone)]
319pub struct EdgeData {
320 pub properties: HashMap<String, Value>,
322 pub weight: f32,
324}
325
326impl EdgeData {
327 pub fn new(weight: f32) -> Self {
329 Self {
330 properties: HashMap::new(),
331 weight,
332 }
333 }
334
335 pub fn with_properties(weight: f32, properties: HashMap<String, Value>) -> Self {
337 Self { properties, weight }
338 }
339
340 pub fn set(&mut self, key: impl Into<String>, value: Value) {
342 self.properties.insert(key.into(), value);
343 }
344
345 pub fn get(&self, key: &str) -> Option<&Value> {
347 self.properties.get(key)
348 }
349}
350
351impl Default for EdgeData {
352 fn default() -> Self {
353 Self::new(1.0)
354 }
355}
356
357#[derive(Debug, Clone)]
359pub struct VectorData {
360 pub dense: Vec<f32>,
362 pub sparse: Option<SparseVector>,
364 pub content: Option<String>,
366}
367
368impl VectorData {
369 pub fn new(dense: Vec<f32>) -> Self {
371 Self {
372 dense,
373 sparse: None,
374 content: None,
375 }
376 }
377
378 pub fn with_sparse(dense: Vec<f32>, sparse: SparseVector) -> Self {
380 Self {
381 dense,
382 sparse: Some(sparse),
383 content: None,
384 }
385 }
386
387 pub fn with_content(mut self, content: impl Into<String>) -> Self {
389 self.content = Some(content.into());
390 self
391 }
392
393 pub fn dimension(&self) -> usize {
395 self.dense.len()
396 }
397
398 pub fn is_hybrid(&self) -> bool {
400 self.sparse.is_some()
401 }
402}
403
404#[derive(Debug, Clone)]
406pub struct TimeSeriesData {
407 pub metric: String,
409 pub series_id: Option<u64>,
411 pub timestamp_ns: u64,
413 pub value: f64,
415 pub tags: std::collections::HashMap<String, String>,
417 pub fields: std::collections::HashMap<String, Value>,
419}
420
421#[derive(Debug, Clone)]
423pub struct QueueMessageData {
424 pub payload: Value,
426 pub priority: Option<i32>,
428 pub enqueued_at_ns: u64,
430 pub attempts: u32,
432 pub max_attempts: u32,
434 pub acked: bool,
436}
437
438#[derive(Debug, Clone)]
440pub struct SparseVector {
441 pub indices: Vec<u32>,
443 pub values: Vec<f32>,
445 pub dimension: usize,
447}
448
449impl SparseVector {
450 pub fn new(indices: Vec<u32>, values: Vec<f32>, dimension: usize) -> Self {
452 debug_assert_eq!(indices.len(), values.len());
453 Self {
454 indices,
455 values,
456 dimension,
457 }
458 }
459
460 pub fn nnz(&self) -> usize {
462 self.indices.len()
463 }
464
465 pub fn sparsity(&self) -> f32 {
467 if self.dimension == 0 {
468 1.0
469 } else {
470 1.0 - (self.nnz() as f32 / self.dimension as f32)
471 }
472 }
473
474 pub fn get(&self, index: u32) -> f32 {
476 self.indices
477 .iter()
478 .position(|&i| i == index)
479 .map(|pos| self.values[pos])
480 .unwrap_or(0.0)
481 }
482}
483
484#[derive(Debug, Clone)]
486pub struct EmbeddingSlot {
487 pub name: String,
489 pub vector: Vec<f32>,
491 pub model: String,
493 pub dimension: usize,
495 pub generated_at: u64,
497}
498
499use crate::clock::current_unix_secs;
500
501impl EmbeddingSlot {
502 pub fn new(name: impl Into<String>, vector: Vec<f32>, model: impl Into<String>) -> Self {
504 let dimension = vector.len();
505 Self {
506 name: name.into(),
507 vector,
508 model: model.into(),
509 dimension,
510 generated_at: current_unix_secs(),
511 }
512 }
513}
514
515#[derive(Debug, Clone)]
517pub struct UnifiedEntity {
518 pub id: EntityId,
520 logical_id: Option<EntityId>,
524 pub kind: EntityKind,
526 pub created_at: u64,
528 pub updated_at: u64,
530 pub data: EntityData,
532 pub sequence_id: u64,
534 pub field_bloom: u64,
545 pub xmin: u64,
554 pub xmax: u64,
560 aux: Option<Box<EntityAux>>,
563}
564
565#[derive(Debug, Clone, Default)]
567pub struct EntityAux {
568 pub embeddings: Vec<EmbeddingSlot>,
570 pub cross_refs: Vec<CrossRef>,
572}
573
574impl UnifiedEntity {
575 pub fn embeddings(&self) -> &[EmbeddingSlot] {
577 self.aux
578 .as_ref()
579 .map(|a| a.embeddings.as_slice())
580 .unwrap_or(&[])
581 }
582
583 pub fn cross_refs(&self) -> &[CrossRef] {
585 self.aux
586 .as_ref()
587 .map(|a| a.cross_refs.as_slice())
588 .unwrap_or(&[])
589 }
590
591 pub fn embeddings_mut(&mut self) -> &mut Vec<EmbeddingSlot> {
593 &mut self.aux.get_or_insert_with(Default::default).embeddings
594 }
595
596 pub fn cross_refs_mut(&mut self) -> &mut Vec<CrossRef> {
598 &mut self.aux.get_or_insert_with(Default::default).cross_refs
599 }
600
601 pub fn has_aux(&self) -> bool {
603 self.aux.is_some()
604 }
605}
606
607#[inline]
613pub fn field_name_bloom(name: &str) -> u64 {
614 let b = name.as_bytes();
615 if b.is_empty() {
616 return 0;
617 }
618 1u64 << (b[b.len() / 2] & 63)
619}
620
621pub fn compute_entity_field_bloom(data: &EntityData) -> u64 {
625 match data {
626 EntityData::Row(row) => {
627 if row.schema.is_some() {
628 return 0;
631 }
632 if let Some(named) = &row.named {
633 let mut bloom = named.keys().fold(0u64, |acc, k| acc | field_name_bloom(k));
634 if let Some(Value::Json(bytes)) = named.get("body") {
642 if let Ok(names) = reddb_types::document_body_codec::field_names(bytes) {
643 for name in names {
644 bloom |= field_name_bloom(&name);
645 }
646 }
647 }
648 bloom
649 } else {
650 0
651 }
652 }
653 EntityData::Node(node) => node
654 .properties
655 .keys()
656 .fold(0u64, |acc, k| acc | field_name_bloom(k)),
657 EntityData::Edge(edge) => edge
658 .properties
659 .keys()
660 .fold(0u64, |acc, k| acc | field_name_bloom(k)),
661 _ => 0,
663 }
664}
665
666impl UnifiedEntity {
667 pub fn new(id: EntityId, kind: EntityKind, data: EntityData) -> Self {
669 let now = current_unix_secs();
670 let field_bloom = compute_entity_field_bloom(&data);
671
672 Self {
673 id,
674 logical_id: None,
675 kind,
676 created_at: now,
677 updated_at: now,
678 data,
679 sequence_id: 0,
680 field_bloom,
681 xmin: 0,
684 xmax: 0,
685 aux: None,
686 }
687 }
688
689 #[inline]
700 pub fn is_visible(&self, snapshot_xid: u64) -> bool {
701 if self.xmin != 0 && self.xmin > snapshot_xid {
702 return false;
703 }
704 if self.xmax != 0 && self.xmax <= snapshot_xid {
705 return false;
706 }
707 true
708 }
709
710 #[inline]
713 pub fn set_xmin(&mut self, xid: u64) {
714 self.xmin = xid;
715 }
716
717 #[inline]
721 pub fn set_xmax(&mut self, xid: u64) {
722 self.xmax = xid;
723 }
724
725 #[inline]
728 pub fn logical_id(&self) -> EntityId {
729 self.logical_id.unwrap_or(self.id)
730 }
731
732 #[inline]
734 pub fn has_explicit_logical_id(&self) -> bool {
735 self.logical_id.is_some()
736 }
737
738 #[inline]
740 pub fn set_logical_id(&mut self, logical_id: EntityId) {
741 self.logical_id = Some(logical_id);
742 }
743
744 #[inline]
756 pub fn ensure_table_logical_id(&mut self) {
757 if self.logical_id.is_none()
758 && matches!(
759 self.kind,
760 EntityKind::TableRow { .. } | EntityKind::GraphNode(_) | EntityKind::GraphEdge(_)
761 )
762 {
763 self.logical_id = Some(self.id);
764 }
765 }
766
767 pub fn table_row(
769 id: EntityId,
770 table: impl Into<Arc<str>>,
771 row_id: u64,
772 columns: Vec<Value>,
773 ) -> Self {
774 Self::new(
775 id,
776 EntityKind::TableRow {
777 table: table.into(),
778 row_id,
779 },
780 EntityData::Row(RowData::new(columns)),
781 )
782 }
783
784 pub fn graph_node(
786 id: EntityId,
787 label: impl Into<String>,
788 node_type: impl Into<String>,
789 properties: HashMap<String, Value>,
790 ) -> Self {
791 Self::new(
792 id,
793 EntityKind::GraphNode(Box::new(GraphNodeKind {
794 label: label.into(),
795 node_type: node_type.into(),
796 })),
797 EntityData::Node(NodeData::with_properties(properties)),
798 )
799 }
800
801 pub fn graph_edge(
803 id: EntityId,
804 label: impl Into<String>,
805 from: impl Into<String>,
806 to: impl Into<String>,
807 weight: f32,
808 properties: HashMap<String, Value>,
809 ) -> Self {
810 Self::new(
811 id,
812 EntityKind::GraphEdge(Box::new(GraphEdgeKind {
813 label: label.into(),
814 from_node: from.into(),
815 to_node: to.into(),
816 weight: (weight * 1000.0) as u32,
817 })),
818 EntityData::Edge(EdgeData::with_properties(weight, properties)),
819 )
820 }
821
822 pub fn vector(id: EntityId, collection: impl Into<String>, vector: Vec<f32>) -> Self {
824 Self::new(
825 id,
826 EntityKind::Vector {
827 collection: collection.into(),
828 },
829 EntityData::Vector(VectorData::new(vector)),
830 )
831 }
832
833 pub fn add_embedding(&mut self, slot: EmbeddingSlot) {
835 self.embeddings_mut().push(slot);
836 self.touch();
837 }
838
839 pub fn add_cross_ref(&mut self, cross_ref: CrossRef) {
841 self.cross_refs_mut().push(cross_ref);
842 self.touch();
843 }
844
845 pub fn get_embedding(&self, name: &str) -> Option<&EmbeddingSlot> {
847 self.embeddings().iter().find(|e| e.name == name)
848 }
849
850 fn touch(&mut self) {
852 self.updated_at = current_unix_secs();
853 }
854
855 pub fn is_stale(&self, max_age_secs: u64) -> bool {
857 let now = current_unix_secs();
858 now.saturating_sub(self.updated_at) > max_age_secs
859 }
860}
861
862#[derive(Debug, Clone, PartialEq)]
864pub struct CrossRef {
865 pub source: EntityId,
867 pub target: EntityId,
869 pub target_collection: String,
871 pub ref_type: RefType,
873 pub weight: f32,
875 pub created_at: u64,
877}
878
879impl CrossRef {
880 pub fn new(
882 source: EntityId,
883 target: EntityId,
884 target_collection: impl Into<String>,
885 ref_type: RefType,
886 ) -> Self {
887 Self {
888 source,
889 target,
890 target_collection: target_collection.into(),
891 ref_type,
892 weight: 1.0,
893 created_at: current_unix_secs(),
894 }
895 }
896
897 pub fn with_weight(
899 source: EntityId,
900 target: EntityId,
901 target_collection: impl Into<String>,
902 ref_type: RefType,
903 weight: f32,
904 ) -> Self {
905 let mut cr = Self::new(source, target, target_collection, ref_type);
906 cr.weight = weight;
907 cr
908 }
909}
910
911#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
913pub enum RefType {
914 RowToNode, RowToEdge, NodeToRow, RowToVector, VectorToRow, NodeToVector, EdgeToVector, VectorToNode, SimilarTo, RelatedTo, DerivesFrom, Mentions, Contains, DependsOn, }
936
937impl RefType {
938 pub fn inverse(&self) -> Option<Self> {
940 match self {
941 Self::RowToNode => Some(Self::NodeToRow),
942 Self::NodeToRow => Some(Self::RowToNode),
943 Self::RowToVector => Some(Self::VectorToRow),
944 Self::VectorToRow => Some(Self::RowToVector),
945 Self::NodeToVector => Some(Self::VectorToNode),
946 Self::VectorToNode => Some(Self::NodeToVector),
947 Self::SimilarTo => Some(Self::SimilarTo), Self::RelatedTo => Some(Self::RelatedTo), _ => None, }
951 }
952
953 pub fn is_symmetric(&self) -> bool {
955 matches!(self, Self::SimilarTo | Self::RelatedTo)
956 }
957
958 pub fn to_byte(&self) -> u8 {
960 match self {
961 Self::RowToNode => 0,
962 Self::RowToEdge => 1,
963 Self::NodeToRow => 2,
964 Self::RowToVector => 3,
965 Self::VectorToRow => 4,
966 Self::NodeToVector => 5,
967 Self::EdgeToVector => 6,
968 Self::VectorToNode => 7,
969 Self::SimilarTo => 8,
970 Self::RelatedTo => 9,
971 Self::DerivesFrom => 10,
972 Self::Mentions => 11,
973 Self::Contains => 12,
974 Self::DependsOn => 13,
975 }
976 }
977
978 pub fn from_byte(byte: u8) -> Self {
980 match byte {
981 0 => Self::RowToNode,
982 1 => Self::RowToEdge,
983 2 => Self::NodeToRow,
984 3 => Self::RowToVector,
985 4 => Self::VectorToRow,
986 5 => Self::NodeToVector,
987 6 => Self::EdgeToVector,
988 7 => Self::VectorToNode,
989 8 => Self::SimilarTo,
990 9 => Self::RelatedTo,
991 10 => Self::DerivesFrom,
992 11 => Self::Mentions,
993 12 => Self::Contains,
994 13 => Self::DependsOn,
995 _ => Self::RelatedTo, }
997 }
998}
999
1000impl From<Vec<Value>> for RowData {
1002 fn from(columns: Vec<Value>) -> Self {
1003 RowData::new(columns)
1004 }
1005}
1006
1007impl From<HashMap<String, Value>> for NodeData {
1009 fn from(properties: HashMap<String, Value>) -> Self {
1010 NodeData::with_properties(properties)
1011 }
1012}
1013
1014impl From<Vec<f32>> for VectorData {
1016 fn from(dense: Vec<f32>) -> Self {
1017 VectorData::new(dense)
1018 }
1019}
1020
1021impl From<(Vec<f32>, SparseVector)> for VectorData {
1023 fn from((dense, sparse): (Vec<f32>, SparseVector)) -> Self {
1024 VectorData::with_sparse(dense, sparse)
1025 }
1026}
1027
1028impl UnifiedEntity {
1030 pub fn from_properties(
1032 id: EntityId,
1033 label: impl Into<String>,
1034 node_type: impl Into<String>,
1035 properties: impl IntoIterator<Item = (impl Into<String>, Value)>,
1036 ) -> Self {
1037 let props: HashMap<String, Value> =
1038 properties.into_iter().map(|(k, v)| (k.into(), v)).collect();
1039 Self::graph_node(id, label, node_type, props)
1040 }
1041
1042 pub fn into_row(self) -> Option<RowData> {
1044 match self.data {
1045 EntityData::Row(r) => Some(r),
1046 _ => None,
1047 }
1048 }
1049
1050 pub fn into_node(self) -> Option<NodeData> {
1052 match self.data {
1053 EntityData::Node(n) => Some(n),
1054 _ => None,
1055 }
1056 }
1057
1058 pub fn into_edge(self) -> Option<EdgeData> {
1060 match self.data {
1061 EntityData::Edge(e) => Some(e),
1062 _ => None,
1063 }
1064 }
1065
1066 pub fn into_vector(self) -> Option<VectorData> {
1068 match self.data {
1069 EntityData::Vector(v) => Some(v),
1070 _ => None,
1071 }
1072 }
1073}
1074
1075#[cfg(test)]
1076mod tests {
1077 use super::*;
1078
1079 #[test]
1080 fn test_entity_creation() {
1081 let id = EntityId::new(1);
1082 let entity = UnifiedEntity::table_row(
1083 id,
1084 "users",
1085 100,
1086 vec![Value::text("alice".to_string()), Value::Integer(25)],
1087 );
1088
1089 assert!(entity.data.is_row());
1090 assert_eq!(entity.kind.storage_type(), "table");
1091 assert_eq!(entity.kind.collection(), "users");
1092 }
1093
1094 #[test]
1095 fn test_cross_refs() {
1096 let id1 = EntityId::new(1);
1097 let id2 = EntityId::new(2);
1098
1099 let cross_ref = CrossRef::new(id1, id2, "nodes", RefType::RowToNode);
1100 assert_eq!(cross_ref.source, id1);
1101 assert_eq!(cross_ref.target, id2);
1102 assert_eq!(cross_ref.ref_type.inverse(), Some(RefType::NodeToRow));
1103 }
1104
1105 #[test]
1106 fn test_sparse_vector() {
1107 let sparse = SparseVector::new(vec![0, 5, 10], vec![1.0, 2.0, 3.0], 100);
1108
1109 assert_eq!(sparse.nnz(), 3);
1110 assert_eq!(sparse.get(5), 2.0);
1111 assert_eq!(sparse.get(3), 0.0);
1112 assert!(sparse.sparsity() > 0.9);
1113 }
1114
1115 #[test]
1116 fn test_embedding_slots() {
1117 let mut entity = UnifiedEntity::table_row(
1118 EntityId::new(1),
1119 "documents",
1120 1,
1121 vec![Value::text("Hello world".to_string())],
1122 );
1123
1124 entity.add_embedding(EmbeddingSlot::new(
1125 "content",
1126 vec![0.1, 0.2, 0.3],
1127 "text-embedding-3-small",
1128 ));
1129
1130 assert_eq!(entity.embeddings().len(), 1);
1131 assert!(entity.get_embedding("content").is_some());
1132 assert!(entity.get_embedding("summary").is_none());
1133 }
1134}