Reading Data

An Edge Shard offers several ways to read data. query is the similarity search entry point, supporting prefetches, fusion, and reranking. scroll pages through points without scoring them, and retrieve, count, and facet read points and payload statistics directly.

query

Runs a query, optionally combining the results of nested prefetch queries.

def query(self, query: QueryRequest) -> List[ScoredPoint]
pub fn query(&self, request: QueryRequest) -> OperationResult<Vec<ScoredPoint>>

Returns a list of ScoredPoint, ordered by score.

QueryRequest accepts the following parameters:

ParameterTypeDescription
limitintMaximum number of points to return. Required.
offsetintNumber of results to skip.
queryscoring queryWhat to score by. Omit to return points without scoring, honoring the filter alone.
prefetcheslist of PrefetchNested queries whose results this query reranks or fuses.
filterFilterPayload and ID conditions the points must satisfy. Refer to Filtering.
score_thresholdfloatDrop results scoring worse than this value.
paramsSearchParamsSearch-time tuning, such as hnsw_ef and exact.
with_payloadbool, list of str, or PayloadSelectorWhich payload to include.
with_vectorbool or list of strWhich vectors to include.

The query parameter accepts several kinds of scoring:

KindPurpose
QueryVector similarity: nearest neighbor, recommendation, discovery, context, or feedback.
FusionCombine the results of multiple prefetches. Refer to Hybrid Queries.
OrderByOrder by a payload field instead of by similarity.
FormulaRescore prefetch results with an expression over payload and score.
MmrMaximal marginal relevance, trading similarity against diversity.
SampleReturn a sample of points.

Prefetch takes query, limit, filter, score_threshold, params, and its own nested prefetches, so prefetches can be nested to build multi-stage retrieval.

scroll

Pages through points in the shard without scoring them.

def scroll(self, scroll: ScrollRequest) -> Tuple[List[Record], Optional[PointId]]
pub fn scroll(&self, request: ScrollRequest) -> OperationResult<(Vec<Record>, Option<PointId>)>

Returns the matching records and the offset to pass to the next call, or None when the last page has been reached.

ParameterTypeDescription
offsetPointIdStart from this point ID. Pass the offset returned by the previous call.
limitintMaximum number of points to return.
filterFilterPayload and ID conditions the points must satisfy.
with_payloadbool, list of str, or PayloadSelectorWhich payload to include.
with_vectorbool or list of strWhich vectors to include.
order_byOrderByPage in the order of a payload field instead of by point ID.

query_groups

Rust only

Groups query results by a payload field, returning a bounded number of hits per distinct value.

fn query_groups(&self, request: GroupRequest) -> OperationResult<Vec<Group>>

Returns a list of Group, each carrying the group’s key and its hits.

ParameterTypeDescription
queryQueryRequestThe query to run within each group.
group_byJsonPathPayload field to group by.
groupsusizeMaximum number of groups to return.
group_sizeusizeMaximum number of hits per group.

search_matrix

Rust only

Samples points and finds each sample’s nearest neighbors, producing a similarity matrix useful for clustering and visualization.

fn search_matrix(&self, request: SearchMatrixRequest) -> OperationResult<SearchMatrixResponse>

Returns a SearchMatrixResponse with sample_ids and, for each sample, its nearests.

ParameterTypeDescription
sample_sizeusizeNumber of points to sample.
limit_per_sampleusizeNumber of nearest neighbors to find per sampled point.
filterFilterRestrict sampling to matching points.
usingVectorNameBufNamed vector to compare on.

retrieve

Fetches points by ID, without scoring.

def retrieve(
    self,
    point_ids: List[PointId],
    with_payload: Optional[WithPayloadType] = None,
    with_vector: Optional[WithVectorType] = None,
) -> List[Record]
pub fn retrieve(&self, request: RetrieveRequest) -> OperationResult<Vec<Record>>

Returns a list of Record. Points that do not exist are omitted rather than reported as errors.

ParameterDescription
point_idsIDs to fetch.
with_payloadWhich payload to include.
with_vectorWhich vectors to include.

count

Counts the points matching a filter.

def count(self, count: CountRequest) -> int
pub fn count(&self, request: CountRequest) -> OperationResult<usize>

Returns the number of matching points.

ParameterTypeDescription
filterFilterConditions the counted points must satisfy. Omit to count every point.
exactboolCount exactly rather than estimating.

facet

Returns the most common values of a payload field, with a count for each.

def facet(self, facet: FacetRequest) -> FacetResponse
pub fn facet(&self, request: FacetRequest) -> OperationResult<FacetResponse>

Returns a FacetResponse whose hits each carry a value and its count.

ParameterTypeDescription
keyJsonPathPayload field to facet on. Required.
limitintMaximum number of distinct values to return.
exactboolCompute exact counts rather than estimating.
filterFilterRestrict faceting to matching points.

Request Builders

In Rust, the request types follow the fluent builder pattern:

let request = QueryRequestBuilder::new(10)
    .with_payload(WithPayloadInterface::Bool(true))
    .build();

Builders are available for QueryRequest, ScrollRequest, RetrieveRequest, CountRequest, FacetRequest, GroupRequest, SearchMatrixRequest, and Prefetch.

In Python, requests are created through their class constructors.

Was this page useful?

Thank you for your feedback! 🙏

We are sorry to hear that. 😔 You can edit this page on GitHub, or create a GitHub issue.