package
24.1.0-rc5
Repository: https://github.com/hypermodeinc/dgraph.git
Documentation: pkg.go.dev

# README

In Dgraph, we have the abiltity to specify an @index directive for the type vfloat. Here, we want to expand that capability to allow us to specify something like:

myAttribute @index("hnsw-euclidean","maxNeighbors":"5","maxLevels":"5","exponent":"6")

Roughly, this should be read as: I want to specify an HNSW-type vector index using euclidean distance as a metric with maxNeighbors, maxLevels, and exponent being declared as written, and with all other parameters taking on default values. (In the case of specifying an exponent, this should affect the defaults for the other options, but that is something that can be decided by the factory for the hnsw index)!

But this leads to some natural questions: How do I know what option types are allowed? And how do I interpret their types? For example, how do I know that I should interpret "5" as an integer rather than a string?

The solution will be to allow each factory to specify a set of "allowed option types". Hence, we get the AllowedOptions class, which specifies a set of named options and corresponding parsers for the given name.

Now, if we want to populate an Options instance based on the content of myAttribute @index(hnsw(metric:"euclidean",exponent:"6")),

we collect the key-value pairs: "metric":"euclidean" "exponent":"6"

And we can now invoke: allowedOpts := hnswFactory.AllowedOpts() myAttributeIndexOpts := NewOptions()

val, err := allowedOpts.GetParsedOption("exponent", "6") if err != nil { return ErrBadOptionNoBiscuit } myAttributeIndexOpts.SetOpt("exponent", val)

The final resolution of the "puzzle" in fact is to invoke allowedOpts.PopulateOptions(pairs, myAttributeIndexOpts) based on pairs being built from the collection of key-value pairs.

# Functions

Float32OptParser implements OptionParser specifically translating float32 options.
Float64OptParser implements OptionParser specifically translating float64 options.
GetInterfaceOpt(o, whichOpt) will retrieve the option associated with whichOpt from o.
GetOpt(o, whichOpt, defaultValue) will attempt to retrieve the value associated with whichOpt in o.
IntOptParser implements OptionParser specifically translating int options.
No description provided by the author
NewOptions() creates a new instance of Options, allowing a client to then modify it to specify whichever packaged options desired.
StringOptionParser implements OptionParser specifically translating string options (well, it actually just passes in the string value as-is with no modification, but having this allows us to simply implement the OptionParser interface.
UintOptParser implement OptionParser specifically translating uint options.

# Structs

OptionValue pair represents the use of a particular option with a string representation of its intended value.

# Type aliases

AllowedOptions specifies the collection of allowed option kinds, and specifies how to interpret the values.
OptionParser translates a string to a value (assuming that the option value is well-formed).
An Options instance maps the various named options to their specific values.