@@ -88,25 +88,48 @@ func (qv *QdrantVector) SaveEmbeddings(ctx context.Context, docID string, embedd
8888 return nil
8989}
9090
91+ // QueryOpt represents an option for a query. This is the type that should
92+ // be returned from query options functions.
93+ type QueryOpt func (* qdrant.QueryPoints )
94+
95+ // WithLimit sets the limit of the number of documents to return in a query.
96+ func WithLimit (limit uint64 ) QueryOpt {
97+ return func (q * qdrant.QueryPoints ) {
98+ q .Limit = & limit
99+ }
100+ }
101+
102+ // WithScoreThreshold sets the score threshold for a query. The higher the threshold, the more relevant the results.
103+ func WithScoreThreshold (threshold float32 ) QueryOpt {
104+ return func (q * qdrant.QueryPoints ) {
105+ q .ScoreThreshold = & threshold
106+ }
107+ }
108+
91109// QueryRelevantDocuments retrieves the most relevant documents based on a given embedding.
92110//
93111// Parameters:
94112// - ctx: The context for the query.
95113// - embedding: The query embedding.
96114// - limit: The number of documents to return.
115+ // - collection: The collection name to query.
97116//
98117// Returns:
99118// - A slice of QDrantDocument structs containing the most relevant documents.
100119// - An error if the query fails.
101- func (qv * QdrantVector ) QueryRelevantDocuments (ctx context.Context , embedding []float32 , limit int , colllection string ) ([]Document , error ) {
102- limitUint := uint64 (limit ) // Convert limit to uint64
120+ func (qv * QdrantVector ) QueryRelevantDocuments (
121+ ctx context.Context , embedding []float32 , collection string , queryOpts ... QueryOpt ,
122+ ) ([]Document , error ) {
103123 query := & qdrant.QueryPoints {
104- CollectionName : colllection , // Replace with actual collection name
124+ CollectionName : collection , // Replace with actual collection name
105125 Query : qdrant .NewQuery (embedding ... ),
106- Limit : & limitUint ,
107126 WithPayload : qdrant .NewWithPayloadInclude ("content" ),
108127 }
109128
129+ for _ , opt := range queryOpts {
130+ opt (query )
131+ }
132+
110133 response , err := qv .client .Query (ctx , query )
111134 if err != nil {
112135 return nil , fmt .Errorf ("failed to search points: %w" , err )
0 commit comments