Documentation
¶
Index ¶
- Constants
- type Fetch
- type FusionAlgorithm
- type Index
- func (ix *Index) Delete(id string) (ok bool, err error)
- func (ix *Index) DeleteMany(ids []string) (count int, err error)
- func (ix *Index) Fetch(f Fetch) (vectors []Vector, err error)
- func (ix *Index) Info() (info IndexInfo, err error)
- func (ix *Index) ListNamespaces() (namespaces []string, err error)
- func (ix *Index) Namespace(namespace string) (i *Namespace)
- func (ix *Index) Query(q Query) (scores []VectorScore, err error)
- func (ix *Index) QueryData(q QueryData) (scores []VectorScore, err error)
- func (ix *Index) Range(r Range) (vectors RangeVectors, err error)
- func (ix *Index) Reset() (err error)
- func (ix *Index) ResumableQuery(q ResumableQuery) (scores []VectorScore, handle *ResumableQueryHandle, err error)
- func (ix *Index) ResumableQueryData(q ResumableQueryData) (scores []VectorScore, handle *ResumableQueryHandle, err error)
- func (ix *Index) Update(u Update) (ok bool, err error)
- func (ix *Index) Upsert(u Upsert) (err error)
- func (ix *Index) UpsertData(u UpsertData) (err error)
- func (ix *Index) UpsertDataMany(u []UpsertData) (err error)
- func (ix *Index) UpsertMany(u []Upsert) (err error)
- type IndexInfo
- type MetadataUpdateMode
- type Namespace
- func (ns *Namespace) Delete(id string) (ok bool, err error)
- func (ns *Namespace) DeleteMany(ids []string) (count int, err error)
- func (ns *Namespace) DeleteNamespace() error
- func (ns *Namespace) Fetch(f Fetch) (vectors []Vector, err error)
- func (ns *Namespace) Query(q Query) (scores []VectorScore, err error)
- func (ns *Namespace) QueryData(q QueryData) (scores []VectorScore, err error)
- func (ns *Namespace) Range(r Range) (vectors RangeVectors, err error)
- func (ns *Namespace) Reset() (err error)
- func (ns *Namespace) ResumableQuery(q ResumableQuery) (scores []VectorScore, handle *ResumableQueryHandle, err error)
- func (ns *Namespace) ResumableQueryData(q ResumableQueryData) (scores []VectorScore, handle *ResumableQueryHandle, err error)
- func (ns *Namespace) Update(u Update) (ok bool, err error)
- func (ns *Namespace) Upsert(u Upsert) (err error)
- func (ns *Namespace) UpsertData(u UpsertData) (err error)
- func (ns *Namespace) UpsertDataMany(u []UpsertData) (err error)
- func (ns *Namespace) UpsertMany(u []Upsert) (err error)
- type NamespaceInfo
- type Options
- type Query
- type QueryData
- type QueryMode
- type Range
- type RangeVectors
- type ResumableQuery
- type ResumableQueryData
- type ResumableQueryHandle
- type ResumableQueryNext
- type SparseVector
- type Update
- type Upsert
- type UpsertData
- type Vector
- type VectorScore
- type WeightingStrategy
Constants ¶
const ( UrlEnvProperty = "UPSTASH_VECTOR_REST_URL" TokenEnvProperty = "UPSTASH_VECTOR_REST_TOKEN" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fetch ¶
type Fetch struct { // Unique vectors ids to fetch. Ids []string `json:"ids"` // Whether to include vector values in the fetch response. IncludeVectors bool `json:"includeVectors,omitempty"` // Whether to include metadata in the fetch response, if any. IncludeMetadata bool `json:"includeMetadata,omitempty"` // Whether to include data in the query response, if any. IncludeData bool `json:"includeData,omitempty"` }
type FusionAlgorithm ¶ added in v0.7.0
type FusionAlgorithm string
FusionAlgorithm specifies the algorithm to use while fusing scores from dense and sparse components of a hybrid index.
const ( // FusionAlgorithmRRF is reciprocal rank fusion. // // Each sorted score from the dense and sparse indexes are // mapped to 1 / (rank + K), where rank is the order of the // score in the dense or sparse scores and K is a constant // with the value of 60. // // Then, scores from the dense and sparse components are // deduplicated (i.e. if a score for the same vector is present // in both dense and sparse scores, the mapped scores are // added; otherwise individual mapped scores are used) // and the final result is returned as the topK values // of this final list. // // In short, this algorithm just takes the order of the scores // into consideration. FusionAlgorithmRRF FusionAlgorithm = "RRF" // FusionAlgorithmDBSF is distribution based score fusion. // // Each sorted score from the dense and sparse indexes are // normalized as // (s - (mean - 3 * stddev)) / ((mean + 3 * stddev) - (mean - 3 * stddev)) // where s is the score, (mean - 3 * stddev) is the minimum, // and (mean + 3 * stddev) is the maximum tail ends of the distribution. // // Then, scores from the dense and sparse components are // deduplicated (i.e. if a score for the same vector is present // in both dense and sparse scores, the normalized scores are // added; otherwise individual normalized scores are used) // and the final result is returned as the topK values // of this final list. // // In short, this algorithm takes distribution of the scores // into consideration as well, as opposed to the RRF. FusionAlgorithmDBSF FusionAlgorithm = "DBSF" )
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a client for Upstash Vector index.
func NewIndex ¶
NewIndex returns an index client to be used with Upstash Vector with the given url and token.
func NewIndexFromEnv ¶
func NewIndexFromEnv() *Index
NewIndexFromEnv returns an index client to be used with Upstash Vector by reading URL and token from the environment variables.
func NewIndexWith ¶
NewIndexWith returns an index client to be used with Upstash Vector with the given options.
func (*Index) Delete ¶
Delete deletes the vector with the given id in the default namespace and reports whether the vector is deleted. If a vector with the given id is not found, Delete returns false.
func (*Index) DeleteMany ¶
DeleteMany deletes the vectors with the given ids in the default namespace and reports how many of them are deleted.
func (*Index) Fetch ¶
Fetch fetches one or more vectors in the default namespace with the ids passed into f. If IncludeVectors is set to true, the vector values are also returned. If IncludeMetadata is set to true, any associated metadata of the vectors is also returned, if any.
func (*Index) Info ¶
Info returns some information about the index, including:
- Total number of vectors across all namespaces
- Total number of vectors waiting to be indexed across all namespaces
- Total size of the index on disk in bytes
- Vector dimension
- Similarity function used
- per-namespace vector and pending vector counts
func (*Index) ListNamespaces ¶ added in v0.5.0
ListNamespaces returns the list of names of namespaces.
func (*Index) Namespace ¶ added in v0.5.0
Namespace returns a new client associated with the given namespace.
func (*Index) Query ¶
func (ix *Index) Query(q Query) (scores []VectorScore, err error)
Query returns the result of the query for the given vector in the default namespace. When q.TopK is specified, the result will contain at most q.TopK many vectors. The returned list will contain vectors sorted in descending order of score, which correlates with the similarity of the vectors to the given query vector. When q.IncludeVectors is true, values of the vectors are also returned. When q.IncludeMetadata is true, metadata of the vectors are also returned, if any.
func (*Index) QueryData ¶ added in v0.4.0
func (ix *Index) QueryData(q QueryData) (scores []VectorScore, err error)
QueryData returns the result of the query for the given data by converting it to an embedding on the server. When q.TopK is specified, the result will contain at most q.TopK many vectors. The returned list will contain vectors sorted in descending order of score, which correlates with the similarity of the vectors to the given query vector. When q.IncludeVectors is true, values of the vectors are also returned. When q.IncludeMetadata is true, metadata of the vectors are also returned, if any.
func (*Index) Range ¶
func (ix *Index) Range(r Range) (vectors RangeVectors, err error)
Range returns a range of vectors, starting with r.Cursor (inclusive), until the end of the vectors in the index or until the given q.Limit. The initial cursor should be set to "0", and subsequent calls to Range might use the next cursor returned in the response. When r.IncludeVectors is true, values of the vectors are also returned. When r.IncludeMetadata is true, metadata of the vectors are also returned, if any.
func (*Index) Reset ¶
Reset deletes all the vectors in the default namespace of the index and resets it to initial state.
func (*Index) ResumableQuery ¶ added in v0.7.0
func (ix *Index) ResumableQuery(q ResumableQuery) (scores []VectorScore, handle *ResumableQueryHandle, err error)
ResumableQuery starts a resumable query and returns the first page of the result of the query for the given vector in the default namespace. Then, next pages of the query results can be fetched over the returned handle. After all the needed pages of the results are fetched, it is recommended to close to handle to release the acquired resources.
func (*Index) ResumableQueryData ¶ added in v0.7.0
func (ix *Index) ResumableQueryData(q ResumableQueryData) (scores []VectorScore, handle *ResumableQueryHandle, err error)
ResumableQueryData starts a resumable query and returns the first page of the result of the query for the given text data in the default namespace. Then, next pages of the query results can be fetched over the returned handle. After all the needed pages of the results are fetched, it is recommended to close to handle to release the acquired resources.
func (*Index) Update ¶ added in v0.7.0
Update updates a vector value, data, or metadata for the given id for the default namespace of the index and reports whether the vector is updated. If a vector with the given id is not found, Update returns false.
func (*Index) Upsert ¶
Upsert updates or inserts a vector to the default namespace of the index. Additional metadata can also be provided while upserting the vector.
func (*Index) UpsertData ¶ added in v0.4.0
func (ix *Index) UpsertData(u UpsertData) (err error)
UpsertData updates or inserts a vector to the default namespace of the index by converting given raw data to an embedding on the server. Additional metadata can also be provided while upserting the vector.
func (*Index) UpsertDataMany ¶ added in v0.4.0
func (ix *Index) UpsertDataMany(u []UpsertData) (err error)
UpsertDataMany updates or inserts some vectors to the default namespace of the index by converting given raw data to an embedding on the server. Additional metadata can also be provided for each vector.
func (*Index) UpsertMany ¶
UpsertMany updates or inserts some vectors to the default namespace of the index. Additional metadata can also be provided for each vector.
type IndexInfo ¶
type IndexInfo struct { // The number of vectors in the index. VectorCount int `json:"vectorCount"` // The number of vectors that are pending to be indexed. PendingVectorCount int `json:"pendingVectorCount"` // The size of the index on disk in bytes IndexSize int `json:"indexSize"` // The dimension of the vectors. Dimension int `json:"dimension"` // Name of the similarity function used in indexing and queries. SimilarityFunction string `json:"similarityFunction"` // Per-namespace vector and pending vector counts Namespaces map[string]NamespaceInfo `json:"namespaces"` }
type MetadataUpdateMode ¶ added in v0.7.0
type MetadataUpdateMode string
MetadataUpdateMode specifies whether to overwrite the whole metadata while updating it, or patch the metadata (insert new fields or update or delete existing fields) according to the RFC 7396 JSON Merge Patch algorithm.
const ( // MetadataUpdateModeOverwrite overwrites the metadata, // and set it to a new value. MetadataUpdateModeOverwrite MetadataUpdateMode = "OVERWRITE" // MetadataUpdateModePatch patches the metadata according // to the JSON Merge Patch algorithm. MetadataUpdateModePatch MetadataUpdateMode = "PATCH" )
type Namespace ¶ added in v0.5.0
type Namespace struct {
// contains filtered or unexported fields
}
func (*Namespace) Delete ¶ added in v0.5.0
Delete deletes the vector with the given id in the namespace and reports whether the vector is deleted. If a vector with the given id is not found, Delete returns false.
func (*Namespace) DeleteMany ¶ added in v0.5.0
DeleteMany deletes the vectors with the given ids in the namespace and reports how many of them are deleted.
func (*Namespace) DeleteNamespace ¶ added in v0.5.0
DeleteNamespace deletes the given namespace of index if it exists.
func (*Namespace) Fetch ¶ added in v0.5.0
Fetch fetches one or more vectors in the namespace with the ids passed into f. If IncludeVectors is set to true, the vector values are also returned. If IncludeMetadata is set to true, any associated metadata of the vectors is also returned, if any.
func (*Namespace) Query ¶ added in v0.5.0
func (ns *Namespace) Query(q Query) (scores []VectorScore, err error)
Query returns the result of the query for the given vector in the namespace. When q.TopK is specified, the result will contain at most q.TopK many vectors. The returned list will contain vectors sorted in descending order of score, which correlates with the similarity of the vectors to the given query vector. When q.IncludeVectors is true, values of the vectors are also returned. When q.IncludeMetadata is true, metadata of the vectors are also returned, if any.
func (*Namespace) QueryData ¶ added in v0.5.0
func (ns *Namespace) QueryData(q QueryData) (scores []VectorScore, err error)
QueryData returns the result of the query for the given data by converting it to an embedding on the server. When q.TopK is specified, the result will contain at most q.TopK many vectors. The returned list will contain vectors sorted in descending order of score, which correlates with the similarity of the vectors to the given query vector. When q.IncludeVectors is true, values of the vectors are also returned. When q.IncludeMetadata is true, metadata of the vectors are also returned, if any.
func (*Namespace) Range ¶ added in v0.5.0
func (ns *Namespace) Range(r Range) (vectors RangeVectors, err error)
Range returns a range of vectors, starting with r.Cursor (inclusive), until the end of the vectors in the index or until the given q.Limit. The initial cursor should be set to "0", and subsequent calls to Range might use the next cursor returned in the response. When r.IncludeVectors is true, values of the vectors are also returned. When r.IncludeMetadata is true, metadata of the vectors are also returned, if any.
func (*Namespace) Reset ¶ added in v0.5.0
Reset deletes all the vectors in the namespace of the index and resets it to initial state.
func (*Namespace) ResumableQuery ¶ added in v0.7.0
func (ns *Namespace) ResumableQuery(q ResumableQuery) (scores []VectorScore, handle *ResumableQueryHandle, err error)
ResumableQuery starts a resumable query and returns the first page of the result of the query for the given vector in the default namespace. Then, next pages of the query results can be fetched over the returned handle. After all the needed pages of the results are fetched, it is recommended to close to handle to release the acquired resources.
func (*Namespace) ResumableQueryData ¶ added in v0.7.0
func (ns *Namespace) ResumableQueryData(q ResumableQueryData) (scores []VectorScore, handle *ResumableQueryHandle, err error)
ResumableQueryData starts a resumable query and returns the first page of the result of the query for the given text data in the default namespace. Then, next pages of the query results can be fetched over the returned handle. After all the needed pages of the results are fetched, it is recommended to close to handle to release the acquired resources.
func (*Namespace) Update ¶ added in v0.7.0
Update updates a vector value, data, or metadata for the given id in the namespace and reports whether the vector is updated. If a vector with the given id is not found, Update returns false.
func (*Namespace) Upsert ¶ added in v0.5.0
Upsert updates or inserts a vector to the namespace of the index. Additional metadata can also be provided while upserting the vector.
func (*Namespace) UpsertData ¶ added in v0.5.0
func (ns *Namespace) UpsertData(u UpsertData) (err error)
UpsertData updates or inserts a vector to the namespace of the index by converting given raw data to an embedding on the server. Additional metadata can also be provided while upserting the vector.
func (*Namespace) UpsertDataMany ¶ added in v0.5.0
func (ns *Namespace) UpsertDataMany(u []UpsertData) (err error)
UpsertDataMany updates or inserts some vectors to the default namespace of the index by converting given raw data to an embedding on the server. Additional metadata can also be provided for each vector.
func (*Namespace) UpsertMany ¶ added in v0.5.0
UpsertMany updates or inserts some vectors to the default namespace of the index. Additional metadata can also be provided for each vector.
type NamespaceInfo ¶ added in v0.5.0
type Query ¶
type Query struct { // The dense query vector for dense and hybrid indexes. Vector []float32 `json:"vector,omitempty"` // The sparse query vector for sparse and hybrid indexes. SparseVector *SparseVector `json:"sparseVector,omitempty"` // The maximum number of vectors that will // be returned for the query response. TopK int `json:"topK,omitempty"` // Whether to include vector values in the query response. IncludeVectors bool `json:"includeVectors,omitempty"` // Whether to include metadata in the query response, if any. IncludeMetadata bool `json:"includeMetadata,omitempty"` // Whether to include data in the query response, if any. IncludeData bool `json:"includeData,omitempty"` // Query filter Filter any `json:"filter,omitempty"` // Weighting strategy to be used for sparse vectors. // If not provided, no weighting will be used. WeightingStrategy WeightingStrategy `json:"weightingStrategy,omitempty"` // Fusion algorithm to use while fusing scores // from dense and sparse components of a hybrid index. // If not provided, defaults to RRF. FusionAlgorithm FusionAlgorithm `json:"fusionAlgorithm,omitempty"` }
type QueryData ¶ added in v0.4.0
type QueryData struct { // Raw data. // Data will be converted to the vector embedding on the server. Data string `json:"data"` // The maximum number of vectors that will // be returned for the query response. TopK int `json:"topK,omitempty"` // Whether to include vector values in the query response. IncludeVectors bool `json:"includeVectors,omitempty"` // Whether to include metadata in the query response, if any. IncludeMetadata bool `json:"includeMetadata,omitempty"` // Whether to include data in the query response, if any. IncludeData bool `json:"includeData,omitempty"` // Query filter Filter any `json:"filter,omitempty"` // Weighting strategy to be used for sparse vectors. // If not provided, no weighting will be used. WeightingStrategy WeightingStrategy `json:"weightingStrategy,omitempty"` // Fusion algorithm to use while fusing scores // from dense and sparse components of a hybrid index. // If not provided, defaults to RRF. FusionAlgorithm FusionAlgorithm `json:"fusionAlgorithm,omitempty"` // Specifies whether to run the query in only the // dense index, only the sparse index, or in both for hybrid // indexes with Upstash-hosted embedding models. // If not provided, defaults to hybrid query mode. QueryMode QueryMode `json:"queryMode,omitempty"` }
type QueryMode ¶ added in v0.7.0
type QueryMode string
QueryMode for hybrid indexes with Upstash-hosted embedding models.
It specifies whether to run the query in only the dense index, only the sparse index, or in both.
const ( // QueryModeHybrid runs the query in hybrid index mode, // after embedding the raw text data into dense and sparse vectors. // // Query results from the dense and sparse index components // of the hybrid index are fused before returning the result. QueryModeHybrid QueryMode = "HYBRID" // QueryModeDense runs the query in dense index mode, // after embedding the raw text data into a dense vector. // // Only the query results from the dense index component // of the hybrid index is returned. QueryModeDense QueryMode = "DENSE" // QueryModeSparse runs the query in sparse index mode, // after embedding the raw text data into a sparse vector. // // Only the query results from the sparse index component // of the hybrid index is returned. QueryModeSparse QueryMode = "SPARSE" )
type Range ¶
type Range struct { // The cursor to start returning range from (inclusive). Cursor string `json:"cursor,omitempty"` // The maximum number of vectors that will be returned for // the range response. Limit int `json:"limit,omitempty"` // Whether to include vector values in the range response. IncludeVectors bool `json:"includeVectors,omitempty"` // Whether to include metadata in the fetch response, if any. IncludeMetadata bool `json:"includeMetadata,omitempty"` // Whether to include data in the query response, if any. IncludeData bool `json:"includeData,omitempty"` }
type RangeVectors ¶
type ResumableQuery ¶ added in v0.7.0
type ResumableQuery struct { // The dense query vector for dense and hybrid indexes. Vector []float32 `json:"vector,omitempty"` // The sparse query vector for sparse and hybrid indexes. SparseVector *SparseVector `json:"sparseVector,omitempty"` // The maximum number of vectors that will // be returned for the query response. TopK int `json:"topK,omitempty"` // Whether to include vector values in the query response. IncludeVectors bool `json:"includeVectors,omitempty"` // Whether to include metadata in the query response, if any. IncludeMetadata bool `json:"includeMetadata,omitempty"` // Whether to include data in the query response, if any. IncludeData bool `json:"includeData,omitempty"` // Query filter Filter any `json:"filter,omitempty"` // Weighting strategy to be used for sparse vectors. // If not provided, no weighting will be used. WeightingStrategy WeightingStrategy `json:"weightingStrategy,omitempty"` // Fusion algorithm to use while fusing scores // from dense and sparse components of a hybrid index. // If not provided, defaults to RRF. FusionAlgorithm FusionAlgorithm `json:"fusionAlgorithm,omitempty"` // Maximum idle time for the resumable query in seconds. // If not provided, defaults to 1 hour. MaxIdle uint32 `json:"maxIdle,omitempty"` }
type ResumableQueryData ¶ added in v0.7.0
type ResumableQueryData struct { // Raw data. // Data will be converted to the vector embedding on the server. Data string `json:"data"` // The maximum number of vectors that will // be returned for the query response. TopK int `json:"topK,omitempty"` // Whether to include vector values in the query response. IncludeVectors bool `json:"includeVectors,omitempty"` // Whether to include metadata in the query response, if any. IncludeMetadata bool `json:"includeMetadata,omitempty"` // Whether to include data in the query response, if any. IncludeData bool `json:"includeData,omitempty"` // Query filter Filter any `json:"filter,omitempty"` // Weighting strategy to be used for sparse vectors. // If not provided, no weighting will be used. WeightingStrategy WeightingStrategy `json:"weightingStrategy,omitempty"` // Fusion algorithm to use while fusing scores // from dense and sparse components of a hybrid index. // If not provided, defaults to RRF. FusionAlgorithm FusionAlgorithm `json:"fusionAlgorithm,omitempty"` // Specifies whether to run the query in only the // dense index, only the sparse index, or in both for hybrid // indexes with Upstash-hosted embedding models. // If not provided, defaults to hybrid query mode. QueryMode QueryMode `json:"queryMode,omitempty"` // Maximum idle time for the resumable query in seconds. // If not provided, defaults to 1 hour. MaxIdle uint32 `json:"maxIdle,omitempty"` }
type ResumableQueryHandle ¶ added in v0.7.0
type ResumableQueryHandle struct {
// contains filtered or unexported fields
}
func (*ResumableQueryHandle) Close ¶ added in v0.7.0
func (h *ResumableQueryHandle) Close() (err error)
Close stops the resumable query and releases the acquired resources.
func (*ResumableQueryHandle) Next ¶ added in v0.7.0
func (h *ResumableQueryHandle) Next(n ResumableQueryNext) (scores []VectorScore, err error)
Next fetches the next page of the query result.
type ResumableQueryNext ¶ added in v0.7.0
type ResumableQueryNext struct {
AdditionalK int `json:"additionalK,omitempty"`
}
type SparseVector ¶ added in v0.7.0
type Update ¶ added in v0.7.0
type Update struct { // The id of the vector to update. Id string `json:"id"` // The new dense vector values for dense and hybrid indexes. Vector []float32 `json:"vector,omitempty"` // The new sparse vector values for sparse and hybrid indexes. SparseVector *SparseVector `json:"sparseVector,omitempty"` // The new data of the vector. Data string `json:"data,omitempty"` // The new metadata of the vector. Metadata map[string]any `json:"metadata,omitempty"` // Whether to overwrite the whole metadata while updating it, // or patch the metadata according to the JSON Merge Patch algorithm. // If not provided, defaults to overwrite. MetadataUpdateMode MetadataUpdateMode `json:"metadataUpdateMode,omitempty"` }
type Upsert ¶
type Upsert struct { // Unique id of the vector. Id string `json:"id"` // Dense vector values for dense and hybrid indexes. Vector []float32 `json:"vector,omitempty"` // Sparse vector values for sparse and hybrid indexes. SparseVector *SparseVector `json:"sparseVector,omitempty"` // Optional data of the vector. Data string `json:"data,omitempty"` // Optional metadata of the vector. Metadata map[string]any `json:"metadata,omitempty"` }
type UpsertData ¶ added in v0.4.0
type Vector ¶
type Vector struct { // Unique id of the vector. Id string `json:"id"` // Dense vector values for dense and hybrid indexes. Vector []float32 `json:"vector,omitempty"` // Sparse vector values for sparse and hybrid indexes. SparseVector *SparseVector `json:"sparseVector,omitempty"` // Optional metadata of the vector, if any. Metadata map[string]any `json:"metadata,omitempty"` // Optional data of the vector. Data string `json:"data,omitempty"` }
type VectorScore ¶
type VectorScore struct { // Unique id of the vector. Id string `json:"id"` // Similarity score of the vector to the query vector. // Vectors more similar to the query vector have higher score. Score float32 `json:"score"` // Optional dense vector values for dense and hybrid indexes. Vector []float32 `json:"vector,omitempty"` // Optional sparse vector values for sparse and hybrid indexes. SparseVector *SparseVector `json:"sparseVector,omitempty"` // Optional metadata of the vector, if any. Metadata map[string]any `json:"metadata,omitempty"` // Optional data of the vector. Data string `json:"data,omitempty"` }
type WeightingStrategy ¶ added in v0.7.0
type WeightingStrategy string
WeightingStrategy specifies what kind of weighting strategy should be used while querying the matching non-zero dimension values of the query vector with the indexed vectors for sparse vectors.
const ( // WeightingStrategyIDF uses inverse document frequencies. // // It is recommended to use this weighting strategy for // BM25 sparse embedding models. // // It is calculated as // ln(((N - n(q) + 0.5) / (n(q) + 0.5)) + 1) where // N: Total number of sparse vectors. // n(q): Total number of sparse vectors having non-zero value // for that particular dimension. // ln: Natural logarithm // The values of N and n(q) are maintained by Upstash as the // vectors are indexed. WeightingStrategyIDF WeightingStrategy = "IDF" )