Skip to content

Commit 5c137ac

Browse files
authored
fix: metadata deserialization/type issue in GetResult struct (#25)
* fix: incorrect metadata deserialization in GetResult struct * test: add test_get_all_metadatas_from_collection to verify metadata serialization and retrieval
1 parent 0cbccfe commit 5c137ac

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/collection.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl ChromaCollection {
362362
#[derive(Deserialize, Debug)]
363363
pub struct GetResult {
364364
pub ids: Vec<String>,
365-
pub metadatas: Option<Vec<Option<Vec<Option<Metadata>>>>>,
365+
pub metadatas: Option<Vec<Option<Metadata>>>,
366366
pub documents: Option<Vec<Option<String>>>,
367367
pub embeddings: Option<Vec<Option<Embedding>>>,
368368
}
@@ -751,6 +751,55 @@ mod tests {
751751
assert_eq!(get_all_result.ids.len(), collection.count().await.unwrap());
752752
}
753753

754+
#[tokio::test]
755+
async fn test_get_all_metadatas_from_collection() {
756+
let client = ChromaClient::new(Default::default());
757+
758+
let collection = client
759+
.await
760+
.unwrap()
761+
.get_or_create_collection(TEST_COLLECTION, None)
762+
.await
763+
.unwrap();
764+
765+
let test_metadatas = vec![
766+
json!({"key1": "value1"}).as_object().unwrap().clone(),
767+
json!({"key2": "value2"}).as_object().unwrap().clone(),
768+
];
769+
770+
let collection_entries = CollectionEntries {
771+
ids: vec!["test1", "test2"],
772+
metadatas: Some(test_metadatas),
773+
documents: Some(vec!["Document content 1", "Document content 2"]),
774+
embeddings: None,
775+
};
776+
777+
let response = collection.add(collection_entries, Some(Box::new(MockEmbeddingProvider)));
778+
assert!(response.await.is_ok());
779+
780+
let get_query = GetOptions {
781+
ids: vec![],
782+
where_metadata: None,
783+
limit: None,
784+
offset: None,
785+
where_document: None,
786+
include: Some(vec!["metadatas".into()]),
787+
};
788+
789+
let get_result = collection.get(get_query).await.unwrap();
790+
791+
assert!(
792+
get_result.metadatas.is_some(),
793+
"Expected metadata to be present in the response"
794+
);
795+
796+
assert_eq!(
797+
get_result.metadatas.unwrap().len(),
798+
2,
799+
"Expected two metadata entries in the response"
800+
);
801+
}
802+
754803
#[tokio::test]
755804
async fn test_update_collection() {
756805
let client = ChromaClient::new(Default::default());

0 commit comments

Comments
 (0)