MCPcopy
hub / github.com/dgraph-io/dgraph / handleValuePostings

Method handleValuePostings

worker/task.go:337–634  ·  view source on GitHub ↗

Handles fetching of value posting lists and filtering of uids based on that.

(ctx context.Context, args funcArgs)

Source from the content-addressed store, hash-verified

335
336// Handles fetching of value posting lists and filtering of uids based on that.
337func (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 {

Callers 1

helpProcessTaskMethod · 0.95

Calls 15

SpanTimerFunction · 0.92
SafeUTF8Function · 0.92
NewQueryCacheFunction · 0.92
NewViLocalCacheFunction · 0.92
ParseAttrFunction · 0.92
DivideAndRuleFunction · 0.92
AssertTrueFunction · 0.92
StateFunction · 0.92
DataKeyFunction · 0.92
TypeIDTypeAlias · 0.92
ConvertFunction · 0.92
CompareValsFunction · 0.92

Tested by

no test coverage detected