|
27 | 27 | import com.apple.foundationdb.async.AsyncUtil; |
28 | 28 | import com.apple.foundationdb.async.MoreAsyncUtil; |
29 | 29 | import com.apple.foundationdb.linear.AffineOperator; |
30 | | -import com.apple.foundationdb.linear.DoubleRealVector; |
31 | 30 | import com.apple.foundationdb.linear.Estimator; |
32 | 31 | import com.apple.foundationdb.linear.FhtKacRotator; |
33 | 32 | import com.apple.foundationdb.linear.Metric; |
|
61 | 60 | import java.util.concurrent.CompletableFuture; |
62 | 61 | import java.util.concurrent.Executor; |
63 | 62 | import java.util.concurrent.PriorityBlockingQueue; |
64 | | -import java.util.concurrent.atomic.AtomicLong; |
65 | 63 | import java.util.concurrent.atomic.AtomicReference; |
66 | 64 | import java.util.function.BiFunction; |
67 | 65 | import java.util.function.Consumer; |
@@ -606,46 +604,12 @@ public OnReadListener getOnReadListener() { |
606 | 604 | return onReadListener; |
607 | 605 | } |
608 | 606 |
|
609 | | - @Nonnull |
610 | | - @SuppressWarnings("PMD.UseUnderscoresInNumericLiterals") |
611 | | - DoubleRealVector centroid() { |
612 | | - final double[] centroidData = {29.0548, 16.785500000000003, 10.708300000000001, 9.7645, 11.3086, 13.3, |
613 | | - 15.288300000000001, 17.6192, 32.8404, 31.009500000000003, 35.9102, 21.5091, 16.005300000000002, 28.0939, |
614 | | - 32.1253, 22.924, 36.2481, 22.5343, 36.420500000000004, 29.186500000000002, 16.4631, 19.899800000000003, |
615 | | - 30.530800000000003, 34.2486, 27.014100000000003, 15.5669, 17.084600000000002, 17.197100000000002, |
616 | | - 14.266, 9.9115, 9.4123, 17.4541, 56.876900000000006, 24.6039, 13.7209, 16.6006, 22.0627, 27.7478, |
617 | | - 24.7289, 27.4496, 61.2528, 41.6972, 36.5536, 23.1854, 23.075200000000002, 37.342800000000004, 35.1334, |
618 | | - 30.1793, 58.946200000000005, 25.0348, 40.7383, 40.7892, 26.500500000000002, 23.0211, 29.471, 45.475, |
619 | | - 51.758300000000006, 20.662100000000002, 24.361900000000002, 31.923000000000002, 30.0682, |
620 | | - 20.075200000000002, 14.327900000000001, 28.1643, 56.229800000000004, 20.611, 23.8963, 26.3485, 22.6032, |
621 | | - 18.0076, 14.595400000000001, 29.842000000000002, 62.9647, 24.6328, 35.617000000000004, |
622 | | - 34.456700000000005, 22.788600000000002, 23.7647, 33.1924, 49.4097, 57.7928, 37.629000000000005, |
623 | | - 32.409600000000005, 22.2239, 26.907300000000003, 43.5585, 39.6792, 29.811, 52.783300000000004, 23.4802, |
624 | | - 14.2668, 19.1766, 28.8002, 32.9715, 25.8216, 26.553800000000003, 28.622, 15.4585, 16.7753, |
625 | | - 14.228900000000001, 11.7788, 9.0432, 9.502500000000001, 18.150100000000002, 36.7239, 21.61, 33.1623, |
626 | | - 25.9082, 15.449000000000002, 20.7373, 33.7562, 36.1929, 32.265, 29.1111, 32.9189, 20.323900000000002, |
627 | | - 16.6245, 31.5031, 35.2207, 22.3947, 28.102500000000003, 15.747100000000001, 10.4765, 10.4483, 13.3939, |
628 | | - 15.767800000000001, 16.2652, 17.000600000000002}; |
629 | | - return new DoubleRealVector(centroidData); |
630 | | - } |
631 | | - |
632 | | - @Nonnull |
633 | | - @SuppressWarnings("PMD.UseUnderscoresInNumericLiterals") |
634 | | - RealVector centroidRot(@Nonnull final FhtKacRotator rotator) { |
635 | | - final DoubleRealVector centroid = centroid(); |
636 | | - return rotator.applyTranspose(centroid); |
637 | | - } |
638 | | - |
639 | 607 | @Nonnull |
640 | 608 | private AffineOperator storageTransform(@Nullable final AccessInfo accessInfo) { |
641 | 609 | if (accessInfo == null || !accessInfo.canUseRaBitQ()) { |
642 | 610 | return AffineOperator.identity(); |
643 | 611 | } |
644 | 612 |
|
645 | | -// final FhtKacRotator rotator1 = new FhtKacRotator(3, getConfig().getNumDimensions(), 10); |
646 | | -// return new StorageTransform(3, |
647 | | -// getConfig().getNumDimensions(), centroidRot(rotator1)); |
648 | | - |
649 | 613 | return new StorageTransform(accessInfo.getRotatorSeed(), |
650 | 614 | getConfig().getNumDimensions(), Objects.requireNonNull(accessInfo.getCentroid())); |
651 | 615 | } |
@@ -1233,8 +1197,6 @@ public CompletableFuture<Void> insert(@Nonnull final Transaction transaction, |
1233 | 1197 | return insert(transaction, nodeReferenceWithVector.getPrimaryKey(), nodeReferenceWithVector.getVector()); |
1234 | 1198 | } |
1235 | 1199 |
|
1236 | | - public static AtomicLong cK = new AtomicLong(0); |
1237 | | - |
1238 | 1200 | /** |
1239 | 1201 | * Inserts a new vector with its associated primary key into the HNSW graph. |
1240 | 1202 | * <p> |
@@ -1262,13 +1224,9 @@ public CompletableFuture<Void> insert(@Nonnull final Transaction transaction, @N |
1262 | 1224 | logger.trace("new node with key={} selected to be inserted into layer={}", newPrimaryKey, insertionLayer); |
1263 | 1225 | } |
1264 | 1226 |
|
1265 | | - cK.set(newPrimaryKey.getLong(0)); |
1266 | | - |
1267 | 1227 | return StorageAdapter.fetchAccessInfo(getConfig(), transaction, getSubspace(), getOnReadListener()) |
1268 | 1228 | .thenCompose(accessInfo -> { |
1269 | 1229 | final AccessInfo currentAccessInfo; |
1270 | | -// final FhtKacRotator rotator1 = new FhtKacRotator(3, getConfig().getNumDimensions(), 10); |
1271 | | -// final AccessInfo staticAccessInfo = new AccessInfo(accessInfo == null ? null : accessInfo.getEntryNodeReference(), 3, centroidRot(rotator1)); |
1272 | 1230 | final AffineOperator storageTransform = storageTransform(accessInfo); |
1273 | 1231 | final RealVector transformedNewVector = storageTransform.applyInvert(newVector); |
1274 | 1232 | final Quantizer quantizer = quantizer(accessInfo); |
@@ -1376,17 +1334,13 @@ public CompletableFuture<Void> insert(@Nonnull final Transaction transaction, @N |
1376 | 1334 | StorageAdapter.writeAccessInfo(transaction, getSubspace(), newAccessInfo, onWriteListener); |
1377 | 1335 | StorageAdapter.removeAllSampledVectors(transaction, getSubspace()); |
1378 | 1336 | if (logger.isTraceEnabled()) { |
1379 | | - //logger.info("at primary key ={}", newPrimaryKey); |
1380 | 1337 | logger.trace("established rotatorSeed={}, centroid with count={}, centroid={}", |
1381 | 1338 | rotatorSeed, partialCount, transformedCentroid); |
1382 | 1339 | } |
1383 | 1340 | } |
1384 | 1341 | } |
1385 | 1342 | return null; |
1386 | 1343 | }); |
1387 | | -// final FhtKacRotator rotator1 = new FhtKacRotator(3, getConfig().getNumDimensions(), 10); |
1388 | | -// final AccessInfo staticAccessInfo = new AccessInfo(accessInfo == null ? null : accessInfo.getEntryNodeReference(), 3, centroidRot(rotator1)); |
1389 | | -// StorageAdapter.writeAccessInfo(transaction, getSubspace(), staticAccessInfo, onWriteListener); |
1390 | 1344 | } |
1391 | 1345 | } |
1392 | 1346 | return AsyncUtil.DONE; |
@@ -1639,14 +1593,14 @@ layer, getConfig().getM(), getConfig().isExtendCandidates(), nodeCache, newVecto |
1639 | 1593 | // regular vectors) |
1640 | 1594 |
|
1641 | 1595 | final Node<N> newNode = |
1642 | | - nodeFactory.create(newPrimaryKey, quantizer.encode(newVector), |
| 1596 | + nodeFactory.create(newPrimaryKey, newVector, |
1643 | 1597 | NodeReferenceAndNode.getReferences(selectedNeighbors)); |
1644 | 1598 |
|
1645 | 1599 | final NeighborsChangeSet<N> newNodeChangeSet = |
1646 | 1600 | new InsertNeighborsChangeSet<>(new BaseNeighborsChangeSet<>(ImmutableList.of()), |
1647 | 1601 | newNode.getNeighbors()); |
1648 | 1602 |
|
1649 | | - storageAdapter.writeNode(transaction, newNode, layer, newNodeChangeSet); |
| 1603 | + storageAdapter.writeNode(transaction, quantizer, newNode, layer, newNodeChangeSet); |
1650 | 1604 |
|
1651 | 1605 | // create change sets for each selected neighbor and insert new node into them |
1652 | 1606 | final Map<Tuple /* primaryKey */, NeighborsChangeSet<N>> neighborChangeSetMap = |
@@ -1680,8 +1634,8 @@ layer, getConfig().getM(), getConfig().isExtendCandidates(), nodeCache, newVecto |
1680 | 1634 | for (int i = 0; i < selectedNeighbors.size(); i++) { |
1681 | 1635 | final NodeReferenceAndNode<N> selectedNeighbor = selectedNeighbors.get(i); |
1682 | 1636 | final NeighborsChangeSet<N> changeSet = changeSets.get(i); |
1683 | | - storageAdapter.writeNode(transaction, selectedNeighbor.getNode(), |
1684 | | - layer, changeSet); |
| 1637 | + storageAdapter.writeNode(transaction, quantizer, |
| 1638 | + selectedNeighbor.getNode(), layer, changeSet); |
1685 | 1639 | } |
1686 | 1640 | return ImmutableList.copyOf(references); |
1687 | 1641 | }); |
@@ -2053,9 +2007,9 @@ private <N extends NodeReference> void writeLonelyNodeOnLayer(@Nonnull final Qua |
2053 | 2007 | final int layer, |
2054 | 2008 | @Nonnull final Tuple primaryKey, |
2055 | 2009 | @Nonnull final RealVector vector) { |
2056 | | - storageAdapter.writeNode(transaction, |
| 2010 | + storageAdapter.writeNode(transaction, quantizer, |
2057 | 2011 | storageAdapter.getNodeFactory() |
2058 | | - .create(primaryKey, quantizer.encode(vector), ImmutableList.of()), layer, |
| 2012 | + .create(primaryKey, vector, ImmutableList.of()), layer, |
2059 | 2013 | new BaseNeighborsChangeSet<>(ImmutableList.of())); |
2060 | 2014 | if (logger.isTraceEnabled()) { |
2061 | 2015 | logger.trace("written lonely node at key={} on layer={}", primaryKey, layer); |
|
0 commit comments