|
17 | 17 | package io.github.jbellis.jvector.graph.similarity; |
18 | 18 |
|
19 | 19 | import io.github.jbellis.jvector.graph.RandomAccessVectorValues; |
| 20 | +import io.github.jbellis.jvector.graph.RemappedRandomAccessVectorValues; |
20 | 21 | import io.github.jbellis.jvector.quantization.BQVectors; |
21 | 22 | import io.github.jbellis.jvector.quantization.PQVectors; |
22 | 23 | import io.github.jbellis.jvector.vector.VectorSimilarityFunction; |
|
25 | 26 | import io.github.jbellis.jvector.vector.types.VectorFloat; |
26 | 27 | import io.github.jbellis.jvector.vector.types.VectorTypeSupport; |
27 | 28 |
|
28 | | -import java.util.stream.IntStream; |
29 | | - |
30 | 29 | /** |
31 | 30 | * Encapsulates comparing node distances for GraphIndexBuilder. |
32 | 31 | */ |
@@ -88,15 +87,15 @@ public interface BuildScoreProvider { |
88 | 87 | * |
89 | 88 | * Helper method for the special case that mapping between graph node IDs and ravv ordinals is the identity function. |
90 | 89 | */ |
91 | | - static BuildScoreProvider randomAccessScoreProvider(RandomAccessVectorValues ravv, VectorSimilarityFunction similarityFunction) { |
92 | | - return randomAccessScoreProvider(ravv, IntStream.range(0, ravv.size()).toArray(), similarityFunction); |
| 90 | + static BuildScoreProvider randomAccessScoreProvider(RandomAccessVectorValues ravv, int[] graphToRavvOrdMap, VectorSimilarityFunction similarityFunction) { |
| 91 | + return randomAccessScoreProvider(new RemappedRandomAccessVectorValues(ravv, graphToRavvOrdMap), similarityFunction); |
93 | 92 | } |
94 | 93 |
|
95 | 94 | /** |
96 | 95 | * Returns a BSP that performs exact score comparisons using the given RandomAccessVectorValues and VectorSimilarityFunction. |
97 | 96 | * graphToRavvOrdMap maps graph node IDs to ravv ordinals. |
98 | 97 | */ |
99 | | - static BuildScoreProvider randomAccessScoreProvider(RandomAccessVectorValues ravv, int[] graphToRavvOrdMap, VectorSimilarityFunction similarityFunction) { |
| 98 | + static BuildScoreProvider randomAccessScoreProvider(RandomAccessVectorValues ravv, VectorSimilarityFunction similarityFunction) { |
100 | 99 | // We need two sources of vectors in order to perform diversity check comparisons without |
101 | 100 | // colliding. ThreadLocalSupplier makes this a no-op if the RAVV is actually un-shared. |
102 | 101 | var vectors = ravv.threadLocalSupplier(); |
@@ -125,22 +124,22 @@ public VectorFloat<?> approximateCentroid() { |
125 | 124 | @Override |
126 | 125 | public SearchScoreProvider searchProviderFor(VectorFloat<?> vector) { |
127 | 126 | var vc = vectorsCopy.get(); |
128 | | - return DefaultSearchScoreProvider.exact(vector, graphToRavvOrdMap, similarityFunction, vc); |
| 127 | + return DefaultSearchScoreProvider.exact(vector, similarityFunction, vc); |
129 | 128 | } |
130 | 129 |
|
131 | 130 | @Override |
132 | 131 | public SearchScoreProvider searchProviderFor(int node1) { |
133 | 132 | RandomAccessVectorValues randomAccessVectorValues = vectors.get(); |
134 | | - var v = randomAccessVectorValues.getVector(graphToRavvOrdMap[node1]); |
| 133 | + var v = randomAccessVectorValues.getVector(node1); |
135 | 134 | return searchProviderFor(v); |
136 | 135 | } |
137 | 136 |
|
138 | 137 | @Override |
139 | 138 | public SearchScoreProvider diversityProviderFor(int node1) { |
140 | 139 | RandomAccessVectorValues randomAccessVectorValues = vectors.get(); |
141 | | - var v = randomAccessVectorValues.getVector(graphToRavvOrdMap[node1]); |
| 140 | + var v = randomAccessVectorValues.getVector(node1); |
142 | 141 | var vc = vectorsCopy.get(); |
143 | | - return DefaultSearchScoreProvider.exact(v, graphToRavvOrdMap, similarityFunction, vc); |
| 142 | + return DefaultSearchScoreProvider.exact(v, similarityFunction, vc); |
144 | 143 | } |
145 | 144 | }; |
146 | 145 | } |
|
0 commit comments