Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions qdrant/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ func NewMatchPhrase(field, phrase string) *Condition {
}
}

// Creates a condition that matches any word in the text.
func NewMatchTextAny(field, textAny string) *Condition {
return &Condition{
ConditionOneOf: &Condition_Field{
Field: &FieldCondition{
Key: field,
Match: &Match{
MatchValue: &Match_TextAny{
TextAny: textAny,
},
},
},
},
}
}

// Creates a condition that checks if a specified field is null.
// See: https://qdrant.tech/documentation/concepts/filtering/#is-null
func NewIsNull(field string) *Condition {
Expand Down
41 changes: 30 additions & 11 deletions qdrant/oneof_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package qdrant

import "google.golang.org/protobuf/types/known/timestamppb"
import (
"google.golang.org/protobuf/types/known/timestamppb"
)

// Creates a *VectorsConfig instance from *VectorParams.
func NewVectorsConfig(params *VectorParams) *VectorsConfig {
Expand Down Expand Up @@ -543,30 +545,38 @@ func NewVector(values ...float32) *Vector {
// Creates a *Vector instance for dense vectors.
func NewVectorDense(vector []float32) *Vector {
return &Vector{
Data: vector,
Vector: &Vector_Dense{
Dense: &DenseVector{
Data: vector,
},
},
}
}

// Creates a *Vector instance for sparse vectors.
func NewVectorSparse(indices []uint32, values []float32) *Vector {
return &Vector{
Data: values,
Indices: &SparseIndices{
Data: indices,
Vector: &Vector_Sparse{
Sparse: &SparseVector{
Indices: indices,
Values: values,
},
},
}
}

// Creates a *Vector instance for multi vectors.
func NewVectorMulti(vectors [][]float32) *Vector {
vectorsCount := uint32(len(vectors))
var flattenedVec []float32
for _, vector := range vectors {
flattenedVec = append(flattenedVec, vector...)
denseVecs := make([]*DenseVector, len(vectors))
for i, vector := range vectors {
denseVecs[i] = &DenseVector{Data: vector}
}
return &Vector{
Data: flattenedVec,
VectorsCount: &vectorsCount,
Vector: &Vector_MultiDense{
MultiDense: &MultiDenseVector{
Vectors: denseVecs,
},
},
}
}

Expand Down Expand Up @@ -755,6 +765,15 @@ func NewQueryFusion(fusion Fusion) *Query {
}
}

// Creates a *Query instance for combining prefetch results with RRF (Reciprocal Rank Fusion).
func NewQueryRRF(rrf *Rrf) *Query {
return &Query{
Variant: &Query_Rrf{
Rrf: rrf,
},
}
}

// Creates a *Query instance for sampling points.
func NewQuerySample(sample Sample) *Query {
return &Query{
Expand Down
84 changes: 84 additions & 0 deletions qdrant/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,87 @@ func (c *Client) SearchMatrixOffsets(ctx context.Context, request *SearchMatrixP
}
return resp.GetResult(), nil
}

// GetDense returns the DenseVector from the VectorOutput.
// Returns nil if no dense vector data is available.
func (v *VectorOutput) GetDenseVector() *DenseVector {
if v == nil {
return nil
}

// Check deprecated data field first
if data := v.GetData(); len(data) > 0 {
return &DenseVector{Data: data}
}

if vector := v.GetVector(); vector != nil {
if dense, ok := vector.(*VectorOutput_Dense); ok && dense != nil {
return dense.Dense
}
}

return nil
}

// GetSparse returns the SparseVector from the VectorOutput.
// Returns nil if no sparse vector data is available.
func (v *VectorOutput) GetSparseVector() *SparseVector {
if v == nil {
return nil
}

// Check deprecated data field first
if data := v.GetData(); len(data) > 0 {
indices := v.GetIndices()
if indices == nil {
return nil
}
return &SparseVector{
Values: data,
Indices: indices.GetData(),
}
}

if vector := v.GetVector(); vector != nil {
if sparse, ok := vector.(*VectorOutput_Sparse); ok && sparse != nil {
return sparse.Sparse
}
}

return nil
}

// GetMultiDense returns the MultiDenseVector from the VectorOutput.
// Returns nil if no multi-dense vector data is available.
func (v *VectorOutput) GetMultiVector() *MultiDenseVector {
if v == nil {
return nil
}

// Check deprecated data field first
if data := v.GetData(); len(data) > 0 {
vectorsCount := v.GetVectorsCount()
if vectorsCount == 0 {
return nil
}

vectorSize := len(data) / int(vectorsCount)
vectors := make([]*DenseVector, int(vectorsCount))

for i := range vectors {
start := i * vectorSize
end := start + vectorSize
vectors[i] = &DenseVector{Data: data[start:end]}
}

return &MultiDenseVector{Vectors: vectors}
}

if vector := v.GetVector(); vector != nil {
if multiDense, ok := vector.(*VectorOutput_MultiDense); ok && multiDense != nil {
return multiDense.MultiDense
}
}

return nil
}