Handles fetching of value posting lists and filtering of uids based on that.
(ctx context.Context, args funcArgs)
| 335 | |
| 336 | // Handles fetching of value posting lists and filtering of uids based on that. |
| 337 | func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) error { |
| 338 | srcFn := args.srcFn |
| 339 | q := args.q |
| 340 | |
| 341 | facetsTree, err := preprocessFilter(q.FacetsFilter) |
| 342 | if err != nil { |
| 343 | return err |
| 344 | } |
| 345 | |
| 346 | span := trace.SpanFromContext(ctx) |
| 347 | stop := x.SpanTimer(span, "handleValuePostings") |
| 348 | defer stop() |
| 349 | span.AddEvent("Number of uids and args.srcFn", trace.WithAttributes( |
| 350 | attribute.Int64("uids_count", int64(srcFn.n)), |
| 351 | attribute.String("srcFn", x.SafeUTF8(fmt.Sprintf("%+v", args.srcFn))))) |
| 352 | |
| 353 | switch srcFn.fnType { |
| 354 | case notAFunction, aggregatorFn, passwordFn, compareAttrFn, similarToFn: |
| 355 | default: |
| 356 | return errors.Errorf("Unhandled function in handleValuePostings: %s", srcFn.fname) |
| 357 | } |
| 358 | |
| 359 | if srcFn.fnType == similarToFn { |
| 360 | numNeighbors, err := strconv.ParseInt(q.SrcFunc.Args[0], 10, 32) |
| 361 | if err != nil { |
| 362 | return fmt.Errorf("invalid value for number of neighbors: %s", q.SrcFunc.Args[0]) |
| 363 | } |
| 364 | cspec, err := pickFactoryCreateSpec(ctx, args.q.Attr) |
| 365 | if err != nil { |
| 366 | return err |
| 367 | } |
| 368 | //TODO: generate maxLevels from schema, filter, etc. |
| 369 | qc := hnsw.NewQueryCache( |
| 370 | posting.NewViLocalCache(qs.cache), |
| 371 | args.q.ReadTs, |
| 372 | ) |
| 373 | indexer, err := cspec.CreateIndex(args.q.Attr) |
| 374 | if err != nil { |
| 375 | return err |
| 376 | } |
| 377 | var nnUids []uint64 |
| 378 | // Build optional search options if provided |
| 379 | filter := index.AcceptAll[float32] |
| 380 | opts := index.VectorIndexOptions[float32]{Filter: filter} |
| 381 | if srcFn.vsEfOverride > 0 { |
| 382 | opts.EfOverride = srcFn.vsEfOverride |
| 383 | } |
| 384 | if srcFn.vsDistanceThreshold != nil { |
| 385 | opts.DistanceThreshold = srcFn.vsDistanceThreshold |
| 386 | } |
| 387 | hasOptions := opts.EfOverride > 0 || opts.DistanceThreshold != nil |
| 388 | if o, ok := indexer.(index.OptionalSearchOptions[float32]); ok && hasOptions { |
| 389 | if srcFn.vectorInfo != nil { |
| 390 | nnUids, err = o.SearchWithOptions(ctx, qc, srcFn.vectorInfo, int(numNeighbors), opts) |
| 391 | } else { |
| 392 | nnUids, err = o.SearchWithUidAndOptions(ctx, qc, srcFn.vectorUid, int(numNeighbors), opts) |
| 393 | } |
| 394 | } else { |
no test coverage detected