Skip to content

Commit 0f97c6f

Browse files
authored
fix(qdrant): serialize values to JSON in the standard way (#587)
1 parent 1702504 commit 0f97c6f

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

src/ops/storages/qdrant.rs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use qdrant_client::qdrant::{
1212
PointsIdsList, UpsertPointsBuilder, Value as QdrantValue, VectorParamsBuilder,
1313
VectorsConfigBuilder,
1414
};
15-
use serde_json::json;
1615

1716
const DEFAULT_VECTOR_SIMILARITY_METRIC: spec::VectorSimilarityMetric =
1817
spec::VectorSimilarityMetric::CosineSimilarity;
@@ -39,7 +38,7 @@ struct Spec {
3938
////////////////////////////////////////////////////////////
4039

4140
struct FieldInfo {
42-
field_name: String,
41+
field_schema: schema::FieldSchema,
4342
is_qdrant_vector: bool,
4443
}
4544

@@ -241,40 +240,19 @@ fn values_to_payload(
241240
let mut vectors = NamedVectors::default();
242241

243242
for (value, field_info) in value_fields.iter().zip(fields_info.iter()) {
244-
let field_name = &field_info.field_name;
245-
243+
let field_name = &field_info.field_schema.name;
246244
match value {
247-
Value::Basic(basic_value) => {
248-
let json_value: serde_json::Value = match basic_value {
249-
BasicValue::Bytes(v) => String::from_utf8_lossy(v).into(),
250-
BasicValue::Str(v) => v.clone().to_string().into(),
251-
BasicValue::Bool(v) => (*v).into(),
252-
BasicValue::Int64(v) => (*v).into(),
253-
BasicValue::Float32(v) => (*v as f64).into(),
254-
BasicValue::Float64(v) => (*v).into(),
255-
BasicValue::Range(v) => json!({ "start": v.start, "end": v.end }),
256-
BasicValue::Uuid(v) => v.to_string().into(),
257-
BasicValue::Date(v) => v.to_string().into(),
258-
BasicValue::Time(v) => v.to_string().into(),
259-
BasicValue::LocalDateTime(v) => v.to_string().into(),
260-
BasicValue::OffsetDateTime(v) => v.to_string().into(),
261-
BasicValue::TimeDelta(v) => v.to_string().into(),
262-
BasicValue::Json(v) => (**v).clone(),
263-
BasicValue::Vector(v) => {
264-
if field_info.is_qdrant_vector {
265-
let vector = encode_vector(v.as_ref())?;
266-
vectors = vectors.add_vector(field_name, vector);
267-
continue;
268-
}
269-
serde_json::to_value(v)?
270-
}
271-
};
272-
payload.insert(field_name.clone(), json_value.into());
245+
Value::Basic(BasicValue::Vector(v)) if field_info.is_qdrant_vector => {
246+
let vector = encode_vector(v.as_ref())?;
247+
vectors = vectors.add_vector(field_name, vector);
273248
}
274-
Value::Null => {
275-
payload.insert(field_name.clone(), QdrantValue { kind: None });
249+
v => {
250+
let json_value = serde_json::to_value(TypedValue {
251+
t: &field_info.field_schema.value_type.typ,
252+
v,
253+
})?;
254+
payload.insert(field_name.clone(), json_value.into());
276255
}
277-
_ => bail!("Unsupported Value variant: {:?}", value),
278256
}
279257
}
280258

@@ -345,7 +323,7 @@ impl StorageFactoryBase for Factory {
345323
for field in d.value_fields_schema.iter() {
346324
let vector_size = parse_supported_vector_size(&field.value_type.typ);
347325
fields_info.push(FieldInfo {
348-
field_name: field.name.clone(),
326+
field_schema: field.clone(),
349327
is_qdrant_vector: vector_size.is_some(),
350328
});
351329
if let Some(vector_size) = vector_size {

0 commit comments

Comments
 (0)