Skip to content

Commit d0c218b

Browse files
Docs(Indexing): Clarify HNSW index parameters and defaults
port PR #706 in main
1 parent fa7b4e5 commit d0c218b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

docusaurus-docs/docs/dql/predicate-indexing.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,24 @@ The indices available for `float32vector` are as follows.
5353
`hnsw` (**Hierarchical Navigable Small World**) index supports the following parameters
5454
- metric : indicate the metric to use to compute vector similarity. One of `cosine`, `euclidean`, and `dotproduct`. Default is `euclidean`.
5555

56-
- exponent : An integer, represented as a string, roughly representing the number of vectors expected in the index in power of 10. The exponent value,is used to set "reasonable defaults" for HNSW internal tuning parameters. Default is "4" (10^4 vectors).
56+
- exponent : an integer, represented as a string, roughly representing the number of vectors expected in the index in power of 10. The exponent value is used to set "reasonable defaults" for HNSW internal tuning parameters. The default is "3" (10^3 vectors). This is a high-level convenience parameter that acts as a "complexity knob" to scale multiple HNSW parameters simultaneously, namely the `maxlevels`, `efconstruction` and `efsearch`. When you set `exponent: "X"`, Dgraph automatically sets default values for three parameters (only if they're not explicitly specified):
57+
```
58+
maxLevels = X - Number of hierarchical layers
59+
efConstruction = 50 × X - Size of dynamic candidate list during index construction
60+
efSearch = 30 × X - Size of dynamic candidate list during search
61+
```
62+
- maxLevels : an integer, represented as a string, that controls the maximum number of hierarchical layers in the HNSW. Defaults to the `exponent` parameter. More layers = faster search for large datasets but more memory overhead. Fewer layers = slower search but less memory usage.
5763

64+
- efConstruction : an integer, represented as a string, that controls the size of the candidate list during index construction - higher values create better quality graphs but take longer to build. Defaults to 50 times the value of `maxLevels`.
65+
66+
- efSearch : an integer, represented as a string, that controls the size of the candidate list during search queries - higher values improve recall/accuracy but make searches slower. Defaults to 30 times the value of `maxLevels`.
5867

5968
Here are some examples:
6069
```
6170
simple_vector: float32vector @index(hnsw) .
6271
description_vector: float32vector @index(hnsw(metric:"cosine")) .
63-
large_vector: float32vector @index(hnsw(metric:"euclidean",exponent:"6")) .
72+
large_vector: float32vector @index(hnsw(metric:"euclidean", exponent:"6")) .
73+
larger_vector: float32vector @index(hnsw(metric:"euclidean", maxLevels: "7", efConstruction: "250", efSearch: "80"))
6474
```
6575

6676
## DateTime Indices

0 commit comments

Comments
 (0)