Skip to content

Commit

Permalink
default payload return is null + update openAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
generall committed Oct 24, 2021
1 parent 3a7485a commit 29830f9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/redoc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@
"$ref": "#/components/schemas/PayloadType"
},
"description": "Payload storage",
"nullable": true,
"type": "object"
},
"score": {
Expand All @@ -1370,7 +1371,6 @@
},
"required": [
"id",
"payload",
"score",
"version"
],
Expand Down
8 changes: 6 additions & 2 deletions lib/collection/tests/collection_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn test_collection_updater() {
Ok(res) => {
assert_eq!(res.len(), 3);
assert_eq!(res[0].id, 2);
assert_eq!(res[0].payload.len(), 0);
assert!(res[0].payload.is_none());
}
Err(err) => panic!("search failed: {:?}", err),
}
Expand Down Expand Up @@ -121,7 +121,11 @@ async fn test_collection_search_with_payload() {
Ok(res) => {
assert_eq!(res.len(), 2);
assert_eq!(res[0].id, 0);
assert_eq!(res[0].payload.len(), 1);
if let Some(payload) = &res[0].payload {
assert_eq!(payload.len(), 1)
} else {
panic!("Payload was expected")
}
}
Err(err) => panic!("search failed: {:?}", err),
}
Expand Down
7 changes: 4 additions & 3 deletions lib/segment/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ impl SegmentEntry for Segment {
})?;
let payload = if with_payload.enable {
let initial_payload = self.payload(point_id)?;
if let Some(i) = &with_payload.payload_selector {
let processed_payload = if let Some(i) = &with_payload.payload_selector {
i.process(initial_payload)
} else {
initial_payload
}
};
Some(processed_payload)
} else {
TheMap::new()
None
};
Ok(ScoredPoint {
id: point_id,
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct ScoredPoint {
/// Points vector distance to the query vector
pub score: ScoreType,
/// Payload storage
pub payload: TheMap<PayloadKeyType, PayloadType>,
pub payload: Option<TheMap<PayloadKeyType, PayloadType>>,
}

impl Eq for ScoredPoint {}
Expand Down
4 changes: 2 additions & 2 deletions openapi/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,6 @@
"type": "object",
"required": [
"id",
"payload",
"score",
"version"
],
Expand All @@ -1338,7 +1337,8 @@
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/PayloadType"
}
},
"nullable": true
},
"score": {
"description": "Points vector distance to the query vector",
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi-merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,7 @@ components:
additionalProperties:
$ref: '#/components/schemas/PayloadType'
description: Payload storage
nullable: true
type: object
score:
description: Points vector distance to the query vector
Expand All @@ -1539,7 +1540,6 @@ components:
type: integer
required:
- id
- payload
- score
- version
type: object
Expand Down

0 comments on commit 29830f9

Please sign in to comment.