use selene_core::{CancellationChecker, DbString, NodeId, VectorMetric, VectorValue};
use crate::error::GraphResult;
use crate::shared::SharedGraph;
use super::{
VectorCandidateSet, VectorNeighborDirection, VectorNeighborSearchOptions, VectorNodeSearchHit,
VectorSearchError,
};
impl SharedGraph {
pub fn score_vector_nodes(
&self,
property: &DbString,
query: &VectorValue,
candidates: &[NodeId],
metric: VectorMetric,
k: usize,
) -> GraphResult<Vec<VectorNodeSearchHit>> {
self.read()
.score_vector_nodes(property, query, candidates, metric, k)
}
pub fn score_vector_nodes_checked(
&self,
property: &DbString,
query: &VectorValue,
candidates: &[NodeId],
metric: VectorMetric,
k: usize,
checker: CancellationChecker<'_>,
) -> Result<Vec<VectorNodeSearchHit>, VectorSearchError> {
self.read()
.score_vector_nodes_checked(property, query, candidates, metric, k, checker)
}
pub fn score_vector_nodes_batch<C>(
&self,
property: &DbString,
queries: &[VectorValue],
candidate_sets: &[C],
metric: VectorMetric,
k: usize,
) -> GraphResult<Vec<Vec<VectorNodeSearchHit>>>
where
C: AsRef<[NodeId]>,
{
self.read()
.score_vector_nodes_batch(property, queries, candidate_sets, metric, k)
}
pub fn score_vector_nodes_batch_checked<C>(
&self,
property: &DbString,
queries: &[VectorValue],
candidate_sets: &[C],
metric: VectorMetric,
k: usize,
checker: CancellationChecker<'_>,
) -> Result<Vec<Vec<VectorNodeSearchHit>>, VectorSearchError>
where
C: AsRef<[NodeId]>,
{
self.read().score_vector_nodes_batch_checked(
property,
queries,
candidate_sets,
metric,
k,
checker,
)
}
pub fn score_vector_candidate_set(
&self,
property: &DbString,
query: &VectorValue,
candidates: &VectorCandidateSet,
metric: VectorMetric,
k: usize,
) -> GraphResult<Vec<VectorNodeSearchHit>> {
self.read()
.score_vector_candidate_set(property, query, candidates, metric, k)
}
pub fn score_vector_candidate_set_checked(
&self,
property: &DbString,
query: &VectorValue,
candidates: &VectorCandidateSet,
metric: VectorMetric,
k: usize,
checker: CancellationChecker<'_>,
) -> Result<Vec<VectorNodeSearchHit>, VectorSearchError> {
self.read()
.score_vector_candidate_set_checked(property, query, candidates, metric, k, checker)
}
pub fn score_vector_candidate_sets_batch(
&self,
property: &DbString,
queries: &[VectorValue],
candidate_sets: &[VectorCandidateSet],
metric: VectorMetric,
k: usize,
) -> GraphResult<Vec<Vec<VectorNodeSearchHit>>> {
self.read()
.score_vector_candidate_sets_batch(property, queries, candidate_sets, metric, k)
}
pub fn score_vector_candidate_sets_batch_checked(
&self,
property: &DbString,
queries: &[VectorValue],
candidate_sets: &[VectorCandidateSet],
metric: VectorMetric,
k: usize,
checker: CancellationChecker<'_>,
) -> Result<Vec<Vec<VectorNodeSearchHit>>, VectorSearchError> {
self.read().score_vector_candidate_sets_batch_checked(
property,
queries,
candidate_sets,
metric,
k,
checker,
)
}
pub fn score_vector_neighbors(
&self,
property: &DbString,
query: &VectorValue,
anchor: NodeId,
options: VectorNeighborSearchOptions<'_>,
) -> GraphResult<Vec<VectorNodeSearchHit>> {
self.read()
.score_vector_neighbors(property, query, anchor, options)
}
pub fn score_vector_neighbors_checked(
&self,
property: &DbString,
query: &VectorValue,
anchor: NodeId,
options: VectorNeighborSearchOptions<'_>,
checker: CancellationChecker<'_>,
) -> Result<Vec<VectorNodeSearchHit>, VectorSearchError> {
self.read()
.score_vector_neighbors_checked(property, query, anchor, options, checker)
}
pub fn score_vector_neighbors_batch(
&self,
property: &DbString,
queries: &[VectorValue],
anchors: &[NodeId],
options: VectorNeighborSearchOptions<'_>,
) -> GraphResult<Vec<Vec<VectorNodeSearchHit>>> {
self.read()
.score_vector_neighbors_batch(property, queries, anchors, options)
}
pub fn score_vector_neighbors_batch_checked(
&self,
property: &DbString,
queries: &[VectorValue],
anchors: &[NodeId],
options: VectorNeighborSearchOptions<'_>,
checker: CancellationChecker<'_>,
) -> Result<Vec<Vec<VectorNodeSearchHit>>, VectorSearchError> {
self.read()
.score_vector_neighbors_batch_checked(property, queries, anchors, options, checker)
}
pub fn score_vector_expanded_candidate_sets_batch(
&self,
property: &DbString,
queries: &[VectorValue],
root_sets: &[VectorCandidateSet],
options: VectorNeighborSearchOptions<'_>,
) -> GraphResult<Vec<Vec<VectorNodeSearchHit>>> {
self.read()
.score_vector_expanded_candidate_sets_batch(property, queries, root_sets, options)
}
pub fn score_vector_expanded_candidate_sets_batch_checked(
&self,
property: &DbString,
queries: &[VectorValue],
root_sets: &[VectorCandidateSet],
options: VectorNeighborSearchOptions<'_>,
checker: CancellationChecker<'_>,
) -> Result<Vec<Vec<VectorNodeSearchHit>>, VectorSearchError> {
self.read()
.score_vector_expanded_candidate_sets_batch_checked(
property, queries, root_sets, options, checker,
)
}
#[must_use]
pub fn vector_neighbor_candidates(
&self,
anchor: NodeId,
edge_label: &DbString,
direction: VectorNeighborDirection,
) -> VectorCandidateSet {
self.read()
.vector_neighbor_candidates(anchor, edge_label, direction)
}
#[must_use]
pub fn expand_vector_candidate_set(
&self,
roots: &VectorCandidateSet,
edge_label: &DbString,
direction: VectorNeighborDirection,
) -> VectorCandidateSet {
self.read()
.expand_vector_candidate_set(roots, edge_label, direction)
}
pub fn expand_vector_candidate_set_checked(
&self,
roots: &VectorCandidateSet,
edge_label: &DbString,
direction: VectorNeighborDirection,
checker: CancellationChecker<'_>,
) -> Result<VectorCandidateSet, VectorSearchError> {
self.read()
.expand_vector_candidate_set_checked(roots, edge_label, direction, checker)
}
pub fn expand_vector_candidate_sets_batch_checked(
&self,
root_sets: &[VectorCandidateSet],
edge_label: &DbString,
direction: VectorNeighborDirection,
k: usize,
checker: CancellationChecker<'_>,
) -> Result<Vec<VectorCandidateSet>, VectorSearchError> {
self.read().expand_vector_candidate_sets_batch_checked(
root_sets, edge_label, direction, k, checker,
)
}
}