|
3432 | 3432 | } |
3433 | 3433 | var(func: similar_to(ProjectCosine.description_v, 3, val(v1))) { |
3434 | 3434 | v2 as ProjectCosine.description_v |
3435 | | - distance as math((1.0 - ((v1 dot v2) / sqrt( (v1 dot v1) * (v2 dot v2) ) )) / 2.0) |
| 3435 | + distance as math(1.0 - ((v1 dot v2) / sqrt( (v1 dot v1) * (v2 dot v2) ))) |
3436 | 3436 | } |
3437 | 3437 | querySimilarProjectCosineById(func: uid(distance), orderasc: val(distance)) { |
3438 | 3438 | ProjectCosine.id : ProjectCosine.id |
|
3457 | 3457 | query querySimilarProjectCosineByEmbedding($search_vector: float32vector = "[0.1,0.2,0.3,0.4,0.5]") { |
3458 | 3458 | var(func: similar_to(ProjectCosine.description_v, 1, $search_vector)) @filter(type(ProjectCosine)) { |
3459 | 3459 | v2 as ProjectCosine.description_v |
3460 | | - distance as math((1.0 - ( (($search_vector) dot v2) / sqrt( (($search_vector) dot ($search_vector)) * (v2 dot v2) ) )) / 2.0) |
| 3460 | + distance as math(1.0 - ((($search_vector) dot v2) / sqrt( (($search_vector) dot ($search_vector)) * (v2 dot v2) ))) |
3461 | 3461 | } |
3462 | 3462 | querySimilarProjectCosineByEmbedding(func: uid(distance), orderasc: val(distance)) { |
3463 | 3463 | ProjectCosine.id : ProjectCosine.id |
|
3487 | 3487 | } |
3488 | 3488 | var(func: similar_to(ProjectDotProduct.description_v, 3, val(v1))) { |
3489 | 3489 | v2 as ProjectDotProduct.description_v |
3490 | | - distance as math((1.0 - (v1 dot v2)) /2.0) |
| 3490 | + distance as math(1.0 - (v1 dot v2)) |
3491 | 3491 | } |
3492 | 3492 | querySimilarProjectDotProductById(func: uid(distance), orderasc: val(distance)) { |
3493 | 3493 | ProjectDotProduct.id : ProjectDotProduct.id |
|
3512 | 3512 | query querySimilarProjectDotProductByEmbedding($search_vector: float32vector = "[0.1,0.2,0.3,0.4,0.5]") { |
3513 | 3513 | var(func: similar_to(ProjectDotProduct.description_v, 1, $search_vector)) @filter(type(ProjectDotProduct)) { |
3514 | 3514 | v2 as ProjectDotProduct.description_v |
3515 | | - distance as math(( 1.0 - (($search_vector) dot v2)) /2.0) |
| 3515 | + distance as math(1.0 - (($search_vector) dot v2)) |
3516 | 3516 | } |
3517 | 3517 | querySimilarProjectDotProductByEmbedding(func: uid(distance), orderasc: val(distance)) { |
3518 | 3518 | ProjectDotProduct.id : ProjectDotProduct.id |
|
3522 | 3522 | ProjectDotProduct.vector_distance : val(distance) |
3523 | 3523 | } |
3524 | 3524 | } |
| 3525 | +
|
| 3526 | +- name: query similar_to with ef parameter |
| 3527 | + gqlquery: | |
| 3528 | + query { |
| 3529 | + querySimilarProductByEmbedding(by: productVector, topK: 5, vector: [0.1, 0.2, 0.3, 0.4, 0.5], ef: 64) { |
| 3530 | + id |
| 3531 | + title |
| 3532 | + productVector |
| 3533 | + } |
| 3534 | + } |
| 3535 | +
|
| 3536 | + dgquery: |- |
| 3537 | + query querySimilarProductByEmbedding($search_vector: float32vector = "[0.1,0.2,0.3,0.4,0.5]") { |
| 3538 | + var(func: similar_to(Product.productVector, 5, $search_vector, ef: 64)) @filter(type(Product)) { |
| 3539 | + v2 as Product.productVector |
| 3540 | + distance as math(sqrt((v2 - $search_vector) dot (v2 - $search_vector))) |
| 3541 | + } |
| 3542 | + querySimilarProductByEmbedding(func: uid(distance), orderasc: val(distance)) { |
| 3543 | + Product.id : Product.id |
| 3544 | + Product.title : Product.title |
| 3545 | + Product.productVector : Product.productVector |
| 3546 | + dgraph.uid : uid |
| 3547 | + Product.vector_distance : val(distance) |
| 3548 | + } |
| 3549 | + } |
| 3550 | +
|
| 3551 | +- name: query similar_to with distance_threshold parameter |
| 3552 | + gqlquery: | |
| 3553 | + query { |
| 3554 | + querySimilarProductByEmbedding(by: productVector, topK: 10, vector: [0.1, 0.2, 0.3, 0.4, 0.5], distance_threshold: 0.5) { |
| 3555 | + id |
| 3556 | + title |
| 3557 | + productVector |
| 3558 | + } |
| 3559 | + } |
| 3560 | +
|
| 3561 | + dgquery: |- |
| 3562 | + query querySimilarProductByEmbedding($search_vector: float32vector = "[0.1,0.2,0.3,0.4,0.5]") { |
| 3563 | + var(func: similar_to(Product.productVector, 10, $search_vector, distance_threshold: 0.5)) @filter(type(Product)) { |
| 3564 | + v2 as Product.productVector |
| 3565 | + distance as math(sqrt((v2 - $search_vector) dot (v2 - $search_vector))) |
| 3566 | + } |
| 3567 | + querySimilarProductByEmbedding(func: uid(distance), orderasc: val(distance)) { |
| 3568 | + Product.id : Product.id |
| 3569 | + Product.title : Product.title |
| 3570 | + Product.productVector : Product.productVector |
| 3571 | + dgraph.uid : uid |
| 3572 | + Product.vector_distance : val(distance) |
| 3573 | + } |
| 3574 | + } |
| 3575 | +
|
| 3576 | +- name: query similar_to with both ef and distance_threshold parameters |
| 3577 | + gqlquery: | |
| 3578 | + query { |
| 3579 | + querySimilarProductByEmbedding(by: productVector, topK: 8, vector: [0.1, 0.2, 0.3, 0.4, 0.5], ef: 128, distance_threshold: 0.75) { |
| 3580 | + id |
| 3581 | + title |
| 3582 | + productVector |
| 3583 | + } |
| 3584 | + } |
| 3585 | +
|
| 3586 | + dgquery: |- |
| 3587 | + query querySimilarProductByEmbedding($search_vector: float32vector = "[0.1,0.2,0.3,0.4,0.5]") { |
| 3588 | + var(func: similar_to(Product.productVector, 8, $search_vector, ef: 128, distance_threshold: 0.75)) @filter(type(Product)) { |
| 3589 | + v2 as Product.productVector |
| 3590 | + distance as math(sqrt((v2 - $search_vector) dot (v2 - $search_vector))) |
| 3591 | + } |
| 3592 | + querySimilarProductByEmbedding(func: uid(distance), orderasc: val(distance)) { |
| 3593 | + Product.id : Product.id |
| 3594 | + Product.title : Product.title |
| 3595 | + Product.productVector : Product.productVector |
| 3596 | + dgraph.uid : uid |
| 3597 | + Product.vector_distance : val(distance) |
| 3598 | + } |
| 3599 | + } |
| 3600 | +
|
| 3601 | +- name: query vector by id with ef parameter |
| 3602 | + gqlquery: | |
| 3603 | + query { |
| 3604 | + querySimilarProductById(by: productVector, topK: 5, id: "0x1", ef: 64) { |
| 3605 | + id |
| 3606 | + title |
| 3607 | + productVector |
| 3608 | + } |
| 3609 | + } |
| 3610 | +
|
| 3611 | + dgquery: |- |
| 3612 | + query { |
| 3613 | + var(func: eq(Product.id, "0x1")) @filter(type(Product)) { |
| 3614 | + vec as Product.productVector |
| 3615 | + } |
| 3616 | + var() { |
| 3617 | + v1 as max(val(vec)) |
| 3618 | + } |
| 3619 | + var(func: similar_to(Product.productVector, 5, val(v1), ef: 64)) { |
| 3620 | + v2 as Product.productVector |
| 3621 | + distance as math(sqrt((v2 - v1) dot (v2 - v1))) |
| 3622 | + } |
| 3623 | + querySimilarProductById(func: uid(distance), orderasc: val(distance)) { |
| 3624 | + Product.id : Product.id |
| 3625 | + Product.title : Product.title |
| 3626 | + Product.productVector : Product.productVector |
| 3627 | + dgraph.uid : uid |
| 3628 | + Product.vector_distance : val(distance) |
| 3629 | + } |
| 3630 | + } |
| 3631 | +
|
| 3632 | +- name: query vector by id with distance_threshold parameter |
| 3633 | + gqlquery: | |
| 3634 | + query { |
| 3635 | + querySimilarProductById(by: productVector, topK: 10, id: "0x1", distance_threshold: 0.5) { |
| 3636 | + id |
| 3637 | + title |
| 3638 | + productVector |
| 3639 | + } |
| 3640 | + } |
| 3641 | +
|
| 3642 | + dgquery: |- |
| 3643 | + query { |
| 3644 | + var(func: eq(Product.id, "0x1")) @filter(type(Product)) { |
| 3645 | + vec as Product.productVector |
| 3646 | + } |
| 3647 | + var() { |
| 3648 | + v1 as max(val(vec)) |
| 3649 | + } |
| 3650 | + var(func: similar_to(Product.productVector, 10, val(v1), distance_threshold: 0.5)) { |
| 3651 | + v2 as Product.productVector |
| 3652 | + distance as math(sqrt((v2 - v1) dot (v2 - v1))) |
| 3653 | + } |
| 3654 | + querySimilarProductById(func: uid(distance), orderasc: val(distance)) { |
| 3655 | + Product.id : Product.id |
| 3656 | + Product.title : Product.title |
| 3657 | + Product.productVector : Product.productVector |
| 3658 | + dgraph.uid : uid |
| 3659 | + Product.vector_distance : val(distance) |
| 3660 | + } |
| 3661 | + } |
| 3662 | +
|
| 3663 | +- name: query vector by id with both ef and distance_threshold parameters |
| 3664 | + gqlquery: | |
| 3665 | + query { |
| 3666 | + querySimilarProductById(by: productVector, topK: 8, id: "0x1", ef: 128, distance_threshold: 0.75) { |
| 3667 | + id |
| 3668 | + title |
| 3669 | + productVector |
| 3670 | + } |
| 3671 | + } |
| 3672 | +
|
| 3673 | + dgquery: |- |
| 3674 | + query { |
| 3675 | + var(func: eq(Product.id, "0x1")) @filter(type(Product)) { |
| 3676 | + vec as Product.productVector |
| 3677 | + } |
| 3678 | + var() { |
| 3679 | + v1 as max(val(vec)) |
| 3680 | + } |
| 3681 | + var(func: similar_to(Product.productVector, 8, val(v1), ef: 128, distance_threshold: 0.75)) { |
| 3682 | + v2 as Product.productVector |
| 3683 | + distance as math(sqrt((v2 - v1) dot (v2 - v1))) |
| 3684 | + } |
| 3685 | + querySimilarProductById(func: uid(distance), orderasc: val(distance)) { |
| 3686 | + Product.id : Product.id |
| 3687 | + Product.title : Product.title |
| 3688 | + Product.productVector : Product.productVector |
| 3689 | + dgraph.uid : uid |
| 3690 | + Product.vector_distance : val(distance) |
| 3691 | + } |
| 3692 | + } |
0 commit comments