|
1 | 1 | use api::conversions::json::proto_to_json; |
2 | 2 | use api::grpc::conversions::grpc_condition_into_condition; |
3 | | -use api::grpc::qdrant as grpc; |
| 3 | +use api::grpc::{DecayParamsExpression, qdrant as grpc}; |
4 | 4 | use common::types::ScoreType; |
5 | 5 | use itertools::Itertools; |
6 | 6 | use segment::data_types::order_by::OrderBy; |
@@ -457,72 +457,45 @@ impl TryFrom<grpc::Expression> for ExpressionInternal { |
457 | 457 | ExpressionInternal::Log10(Box::new((*expression).try_into()?)) |
458 | 458 | } |
459 | 459 | Variant::Ln(expression) => ExpressionInternal::Ln(Box::new((*expression).try_into()?)), |
460 | | - Variant::ExpDecay(exp_decay_expression) => { |
461 | | - let grpc::DecayParamsExpression { |
462 | | - x, |
463 | | - target, |
464 | | - midpoint, |
465 | | - scale, |
466 | | - } = *exp_decay_expression; |
467 | | - |
468 | | - let x = *x.ok_or_else(|| tonic::Status::invalid_argument("missing field: x"))?; |
469 | | - |
470 | | - let target = target.map(|t| (*t).try_into()).transpose()?.map(Box::new); |
471 | | - |
472 | | - ExpressionInternal::Decay { |
473 | | - kind: DecayKind::Exp, |
474 | | - x: Box::new(x.try_into()?), |
475 | | - target, |
476 | | - midpoint, |
477 | | - scale, |
478 | | - } |
| 460 | + Variant::LinDecay(decay_params) => { |
| 461 | + try_from_decay_params(*decay_params, DecayKind::Lin)? |
479 | 462 | } |
480 | | - Variant::GaussDecay(gauss_decay_expression) => { |
481 | | - let grpc::DecayParamsExpression { |
482 | | - x, |
483 | | - target, |
484 | | - midpoint, |
485 | | - scale, |
486 | | - } = *gauss_decay_expression; |
487 | | - |
488 | | - let x = *x.ok_or_else(|| tonic::Status::invalid_argument("missing field: x"))?; |
489 | | - |
490 | | - let target = target.map(|t| (*t).try_into()).transpose()?.map(Box::new); |
491 | | - |
492 | | - ExpressionInternal::Decay { |
493 | | - kind: DecayKind::Gauss, |
494 | | - x: Box::new(x.try_into()?), |
495 | | - target, |
496 | | - midpoint, |
497 | | - scale, |
498 | | - } |
| 463 | + Variant::ExpDecay(decay_params) => { |
| 464 | + try_from_decay_params(*decay_params, DecayKind::Exp)? |
499 | 465 | } |
500 | | - Variant::LinDecay(lin_decay_expression) => { |
501 | | - let grpc::DecayParamsExpression { |
502 | | - x, |
503 | | - target, |
504 | | - midpoint, |
505 | | - scale, |
506 | | - } = *lin_decay_expression; |
507 | | - |
508 | | - let x = *x.ok_or_else(|| tonic::Status::invalid_argument("missing field: x"))?; |
509 | | - |
510 | | - let target = target.map(|t| (*t).try_into()).transpose()?.map(Box::new); |
511 | | - |
512 | | - ExpressionInternal::Decay { |
513 | | - kind: DecayKind::Lin, |
514 | | - x: Box::new(x.try_into()?), |
515 | | - target, |
516 | | - midpoint, |
517 | | - scale, |
518 | | - } |
| 466 | + Variant::GaussDecay(decay_params) => { |
| 467 | + try_from_decay_params(*decay_params, DecayKind::Gauss)? |
519 | 468 | } |
520 | 469 | }; |
521 | 470 |
|
522 | 471 | Ok(expression) |
523 | 472 | } |
524 | 473 | } |
525 | 474 |
|
| 475 | +fn try_from_decay_params( |
| 476 | + params: DecayParamsExpression, |
| 477 | + kind: DecayKind, |
| 478 | +) -> Result<ExpressionInternal, Status> { |
| 479 | + let grpc::DecayParamsExpression { |
| 480 | + x, |
| 481 | + target, |
| 482 | + midpoint, |
| 483 | + scale, |
| 484 | + } = params; |
| 485 | + |
| 486 | + let x = *x.ok_or_else(|| tonic::Status::invalid_argument("missing field: x"))?; |
| 487 | + |
| 488 | + let target = target.map(|t| (*t).try_into()).transpose()?.map(Box::new); |
| 489 | + |
| 490 | + Ok(ExpressionInternal::Decay { |
| 491 | + kind, |
| 492 | + x: Box::new(x.try_into()?), |
| 493 | + target, |
| 494 | + midpoint, |
| 495 | + scale, |
| 496 | + }) |
| 497 | +} |
| 498 | + |
526 | 499 | impl From<api::grpc::qdrant::Fusion> for FusionInternal { |
527 | 500 | fn from(fusion: api::grpc::qdrant::Fusion) -> Self { |
528 | 501 | match fusion { |
|
0 commit comments