Documentation
¶
Overview ¶
Package search defines the Search building-block contract used by Dapr's search.proto runtime API. Components implement Search to store, retrieve and query index-ready documents in lexical / structured search backends.
Vector similarity is intentionally a separate building block; see the sibling vector package.
Index ¶
- Constants
- func ContinuationExpiredError(msg string) error
- func IndexingOutcomeUnknownError(code codes.Code, msg string) error
- func NewErrorWithReason(code codes.Code, reason, msg string) error
- func ValidateDocumentContent(content []byte) error
- func ValidateIndexingOptions(ctx context.Context, opts IndexingOptions, supportsQueuedAck bool) error
- func ValidateWriteIDs(ids []string) error
- type CreateIndexRequest
- type DeleteDocumentsRequest
- type DeleteDocumentsResponse
- type DeleteIndexRequest
- type Document
- type FailedItem
- type GetDocumentsRequest
- type GetDocumentsResponse
- type GetIndexRequest
- type GetIndexResponse
- type Hit
- type IndexAck
- type IndexDocumentsRequest
- type IndexDocumentsResponse
- type IndexingMode
- type IndexingOptions
- type IndexingWaitTimeoutAction
- type ListIndexesRequest
- type ListIndexesResponse
- type Metadata
- type Search
- type SearchRequest
- type SearchResponse
- type SortClause
- type SortOrder
- type TotalHitsRelation
Constants ¶
const ( // ErrorDomain is the google.rpc.ErrorInfo domain used by search and vector // errors. ErrorDomain = "dapr.io" // ReasonContinuationExpired is set when a provider cursor referenced by a // continuation token has expired. Returned with FAILED_PRECONDITION. ReasonContinuationExpired = "SEARCH_CONTINUATION_EXPIRED" // ReasonIndexingOutcomeUnknown is set when a provider reports a batch-level // failure but cannot establish which items were applied. ReasonIndexingOutcomeUnknown = "INDEXING_OUTCOME_UNKNOWN" )
Variables ¶
This section is empty.
Functions ¶
func ContinuationExpiredError ¶
ContinuationExpiredError returns the FAILED_PRECONDITION error used when a provider cursor has expired.
func IndexingOutcomeUnknownError ¶
IndexingOutcomeUnknownError wraps a batch-level provider failure whose per-item outcome cannot be established.
func NewErrorWithReason ¶
NewErrorWithReason returns a status error with a google.rpc.ErrorInfo detail carrying reason.
func ValidateDocumentContent ¶
ValidateDocumentContent checks that content is a UTF-8 encoded JSON object, the normative alpha document encoding. The returned error is an INVALID_ARGUMENT status suitable for a FailedItem.
func ValidateIndexingOptions ¶
func ValidateIndexingOptions(ctx context.Context, opts IndexingOptions, supportsQueuedAck bool) error
ValidateIndexingOptions validates the portable IndexingOptions rules. supportsQueuedAck reports whether the provider offers a native durable queued acknowledgement; CONTINUE_ASYNC is rejected when it does not. Returned errors are INVALID_ARGUMENT status errors.
func ValidateWriteIDs ¶
ValidateWriteIDs checks that every ID of a keyed upsert is non-empty and unique within the request. Returned errors are INVALID_ARGUMENT status errors.
Types ¶
type CreateIndexRequest ¶
type CreateIndexRequest struct {
Index string
// Component-specific index settings.
Metadata map[string]string
}
CreateIndexRequest is the input to Search.CreateIndex.
type DeleteDocumentsRequest ¶
type DeleteDocumentsRequest struct {
Index string
IDs []string
Metadata map[string]string
Options IndexingOptions
}
DeleteDocumentsRequest is the input to Search.DeleteDocuments. IDs that do not exist are not an error.
type DeleteDocumentsResponse ¶
type DeleteDocumentsResponse struct {
// Always IndexAckQueued or IndexAckCompleted on success.
Ack IndexAck
}
DeleteDocumentsResponse is the output of Search.DeleteDocuments.
type DeleteIndexRequest ¶
DeleteIndexRequest is the input to Search.DeleteIndex.
type Document ¶
type Document struct {
ID string
// Content is a UTF-8 encoded JSON object. Field-level operations address
// its keys with dotted paths. The runtime rejects content that is not a
// JSON object before it reaches the component.
Content []byte
// Metadata is opaque caller metadata stored with the document and
// returned unchanged. It is not indexed or filterable.
Metadata map[string]string
}
Document is a single index-ready document.
type FailedItem ¶
type FailedItem struct {
ID string
// Error carries a canonical, non-OK code.
Error *status.Status
}
FailedItem is an item-specific write failure shared by document indexing and vector upserts.
type GetDocumentsRequest ¶
type GetDocumentsRequest struct {
Index string
IDs []string
IncludeContent bool
Metadata map[string]string
}
GetDocumentsRequest is the input to Search.GetDocuments.
type GetDocumentsResponse ¶
type GetDocumentsResponse struct {
Documents []Document
}
GetDocumentsResponse is the output of Search.GetDocuments. Documents are returned in request order; documents that are not found are omitted.
type GetIndexRequest ¶
GetIndexRequest is the input to Search.GetIndex.
type GetIndexResponse ¶
type GetIndexResponse struct {
Index string
// Approximate document count. Providers that cannot supply this value
// efficiently may return 0.
DocumentCount uint64
Properties map[string]string
}
GetIndexResponse is the output of Search.GetIndex.
type Hit ¶
type Hit struct {
Document Document
// Score is an unnormalized provider-specific relevance score. Higher
// values indicate a more relevant match.
Score float64
Highlights map[string]string
}
Hit is a single result entry returned from a Search call.
type IndexAck ¶
type IndexAck int32
IndexAck is the acknowledgement boundary reached by a write. Mirrors search.proto IndexAck.
const ( // IndexAckUnspecified is never returned by a successful write. IndexAckUnspecified IndexAck = 0 // IndexAckQueued means the provider accepted the request for asynchronous // processing. It does not indicate that any item was applied. IndexAckQueued IndexAck = 1 // IndexAckCompleted means the provider completed the write and // FailedItems contains every item-specific failure. IndexAckCompleted IndexAck = 2 )
type IndexDocumentsRequest ¶
type IndexDocumentsRequest struct {
Index string
Documents []Document
Metadata map[string]string
Options IndexingOptions
}
IndexDocumentsRequest is the input to Search.IndexDocuments. It is a keyed upsert: every document has a non-empty ID that is unique within the request.
type IndexDocumentsResponse ¶
type IndexDocumentsResponse struct {
// Item-specific failures known at the acknowledgement boundary.
FailedItems []FailedItem
// Always IndexAckQueued or IndexAckCompleted on success.
Ack IndexAck
}
IndexDocumentsResponse is the output of Search.IndexDocuments.
type IndexingMode ¶
type IndexingMode int32
IndexingMode selects the acknowledgement boundary a write returns at.
const ( // IndexingModeUnspecified behaves exactly as IndexingModeReturnOnAcceptance. IndexingModeUnspecified IndexingMode = 0 // IndexingModeWaitForCompletion waits for a final provider result. IndexingModeWaitForCompletion IndexingMode = 1 // IndexingModeReturnOnAcceptance returns after the provider durably // accepts the write for background processing. IndexingModeReturnOnAcceptance IndexingMode = 2 )
type IndexingOptions ¶
type IndexingOptions struct {
Mode IndexingMode
WaitTimeout time.Duration
OnWaitTimeout IndexingWaitTimeoutAction
}
IndexingOptions mirrors search.proto IndexingOptionsAlpha1.
type IndexingWaitTimeoutAction ¶
type IndexingWaitTimeoutAction int32
IndexingWaitTimeoutAction selects what happens when WaitTimeout expires.
const ( IndexingWaitTimeoutActionUnspecified IndexingWaitTimeoutAction = 0 // IndexingWaitTimeoutActionContinueAsync returns IndexAckQueued and lets // the durably queued provider task continue. IndexingWaitTimeoutActionContinueAsync IndexingWaitTimeoutAction = 1 // IndexingWaitTimeoutActionFailRequest returns DEADLINE_EXCEEDED. IndexingWaitTimeoutActionFailRequest IndexingWaitTimeoutAction = 2 )
type ListIndexesRequest ¶
ListIndexesRequest is the input to Search.ListIndexes.
type ListIndexesResponse ¶
type ListIndexesResponse struct {
Indexes []string
}
ListIndexesResponse is the output of Search.ListIndexes.
type Search ¶
type Search interface {
metadata.ComponentWithMetadata
// Init is called once per component instance with the resolved metadata.
Init(ctx context.Context, meta Metadata) error
// Index lifecycle.
CreateIndex(ctx context.Context, req *CreateIndexRequest) error
GetIndex(ctx context.Context, req *GetIndexRequest) (*GetIndexResponse, error)
ListIndexes(ctx context.Context, req *ListIndexesRequest) (*ListIndexesResponse, error)
DeleteIndex(ctx context.Context, req *DeleteIndexRequest) error
// Document operations.
IndexDocuments(ctx context.Context, req *IndexDocumentsRequest) (*IndexDocumentsResponse, error)
GetDocuments(ctx context.Context, req *GetDocumentsRequest) (*GetDocumentsResponse, error)
DeleteDocuments(ctx context.Context, req *DeleteDocumentsRequest) (*DeleteDocumentsResponse, error)
// Query.
Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)
io.Closer
}
Search is the Search building-block component contract. Method shapes mirror the alpha1 RPCs in dapr/proto/runtime/v1/search.proto using Go-native types so the runtime can adapt between gRPC, HTTP/JSON and component invocations without leaking proto types into components.
Errors returned by components SHOULD be gRPC status errors carrying a canonical code (see google.golang.org/grpc/status). Other errors are reported to callers as INTERNAL.
type SearchRequest ¶
type SearchRequest struct {
Index string
Text string
Native map[string]any
Filter map[string]any
TopK uint32
ContinuationToken string
ReturnFields []string
IncludeContent bool
SearchFields []string
Sort []SortClause
HighlightFields []string
Metadata map[string]string
}
SearchRequest is the input to Search.Search. Text and Native are mutually exclusive: at most one of them is set. A request with neither matches every document, subject to Filter.
type SearchResponse ¶
type SearchResponse struct {
Hits []Hit
// Best-effort total. Nil when the provider cannot supply one.
TotalHits *uint64
// Opaque token for the next page. Empty when there are no more results.
ContinuationToken string
// Accuracy of TotalHits. Unspecified when TotalHits is nil.
TotalHitsRelation TotalHitsRelation
}
SearchResponse is the output of Search.Search.
type SortClause ¶
SortClause expresses a single sort key.
type SortOrder ¶
type SortOrder int32
SortOrder selects the direction of a sort clause. Mirrors search.proto.
type TotalHitsRelation ¶
type TotalHitsRelation int32
TotalHitsRelation describes the accuracy of SearchResponse.TotalHits.
const ( TotalHitsRelationUnspecified TotalHitsRelation = 0 TotalHitsRelationExact TotalHitsRelation = 1 TotalHitsRelationLowerBound TotalHitsRelation = 2 TotalHitsRelationEstimate TotalHitsRelation = 3 )