Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index Initialization Alloc Method #1933

Conversation

MrFlap
Copy link
Contributor

@MrFlap MrFlap commented Aug 5, 2024

Previously, the iterative index insertion feature only allocated memory for HNSW indices. New functionality for other indices needs to be implemented.

Description

This branch adds a method to allocate an index and adds logic for HNSWSQ indices. The following benchmark was run on a 4gb docker container for COHERE with 1m vectors on HNSWSQ.
graph_default_osb_sqtest-15

Metric Task Value Unit
Min Throughput custom-vector-bulk 754.72 docs/s
Mean Throughput custom-vector-bulk 1420.79 docs/s
Median Throughput custom-vector-bulk 1194.48 docs/s
Max Throughput custom-vector-bulk 3388.12 docs/s
50th percentile latency custom-vector-bulk 221.291 ms
90th percentile latency custom-vector-bulk 470.813 ms
99th percentile latency custom-vector-bulk 23489.8 ms
99.9th percentile latency custom-vector-bulk 69936.4 ms
99.99th percentile latency custom-vector-bulk 83420.9 ms
100th percentile latency custom-vector-bulk 112154 ms
50th percentile service time custom-vector-bulk 221.291 ms
90th percentile service time custom-vector-bulk 470.813 ms
99th percentile service time custom-vector-bulk 23489.8 ms
99.9th percentile service time custom-vector-bulk 69936.4 ms
99.99th percentile service time custom-vector-bulk 83420.9 ms
100th percentile service time custom-vector-bulk 112154 ms
error rate custom-vector-bulk 0 %
Min Throughput force-merge-segments 0 ops/s
Mean Throughput force-merge-segments 0 ops/s
Median Throughput force-merge-segments 0 ops/s
Max Throughput force-merge-segments 0 ops/s
100th percentile latency force-merge-segments 4.24338e+06 ms
100th percentile service time force-merge-segments 4.24338e+06 ms
error rate force-merge-segments 0 %
Min Throughput warmup-indices 0.26 ops/s
Mean Throughput warmup-indices 0.26 ops/s
Median Throughput warmup-indices 0.26 ops/s
Max Throughput warmup-indices 0.26 ops/s
100th percentile latency warmup-indices 3912.27 ms
100th percentile service time warmup-indices 3912.27 ms
error rate warmup-indices 0 %
Min Throughput prod-queries 15.96 ops/s
Mean Throughput prod-queries 131.02 ops/s
Median Throughput prod-queries 138.18 ops/s
Max Throughput prod-queries 144.59 ops/s
50th percentile latency prod-queries 4.74785 ms
90th percentile latency prod-queries 5.54795 ms
99th percentile latency prod-queries 6.62209 ms
99.9th percentile latency prod-queries 10.8428 ms
99.99th percentile latency prod-queries 20.4215 ms
100th percentile latency prod-queries 417.638 ms
50th percentile service time prod-queries 4.74785 ms
90th percentile service time prod-queries 5.54795 ms
99th percentile service time prod-queries 6.62209 ms
99.9th percentile service time prod-queries 10.8428 ms
99.99th percentile service time prod-queries 20.4215 ms
100th percentile service time prod-queries 417.638 ms
error rate prod-queries 0 %
Mean recall@k prod-queries 0.91
Mean recall@1 prod-queries 0.98

Related Issues

#1600

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

jni/src/faiss_index_service.cpp Outdated Show resolved Hide resolved
Comment on lines 63 to 72
indexFlatCodes->codes.reserve(dim * numVectors * 4);
return;
}
if(auto * indexHNSWSQ = dynamic_cast<faiss::IndexHNSWSQ *>(index)) {
auto * indexFlatCodes = dynamic_cast<faiss::IndexFlatCodes *>(indexHNSWSQ->storage);
indexFlatCodes->codes.reserve(dim * numVectors * 2);
return;
}
if(auto * indexFlat = dynamic_cast<faiss::IndexFlat *>(index)) {
indexFlat->codes.reserve(dim * numVectors * 4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can avoid these numbers and send a parameter from Java which tells the number of bytes per dimension. because right now SQ is for fp16 only but there are other SQ which are coming up like byte vector where we want to send 1 byte per dimension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be handled in the faiss layer easily. ScalarQuantizer keeps track of the size of the vector with the specified quantization method. I can make that change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great. this is awesome.

@navneet1v
Copy link
Collaborator

add the entry in the changelog.

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
@navneet1v navneet1v added v2.17.0 Enhancements Increases software capabilities beyond original client specifications indexing-improvements This label should be attached to all the github issues which will help improving the indexing time. labels Aug 7, 2024
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
@navneet1v
Copy link
Collaborator

Overall code looks good to me. I will approve the PR once all CIs are successful,

@MrFlap
Copy link
Contributor Author

MrFlap commented Aug 8, 2024

This backwards compatibility test keeps failing. Don't know what it is

@navneet1v
Copy link
Collaborator

navneet1v commented Aug 8, 2024

This backwards compatibility test keeps failing. Don't know what it is

This is because 2.16 is moved from SNAPSHOT to release. There is a fix needed in main branch. Its a known thing during releases. Hence we can ignore that check for now.

PR: #1940

Lets ensure all the build tasks are successful

@navneet1v
Copy link
Collaborator

@MrFlap with the updated code, please re-run the benchmarks and paste the results. Once we validated the benchmarks with new code I will merge the changes.

@navneet1v navneet1v merged commit e2204c2 into opensearch-project:feature/iterative-index-build Aug 8, 2024
50 of 52 checks passed
@navneet1v
Copy link
Collaborator

Merged the code as the benchmarks are updated with new code.

shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 12, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 13, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 13, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
ryanbogan pushed a commit that referenced this pull request Aug 13, 2024
* Iterative Vector Insertion (#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 14, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
shatejas added a commit to shatejas/k-NN that referenced this pull request Aug 15, 2024
* Iterative Vector Insertion (opensearch-project#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (opensearch-project#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
shatejas added a commit to shatejas/k-NN that referenced this pull request Aug 15, 2024
* Iterative Vector Insertion (opensearch-project#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (opensearch-project#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
shatejas added a commit to shatejas/k-NN that referenced this pull request Aug 15, 2024
* Iterative Vector Insertion (opensearch-project#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (opensearch-project#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
ryanbogan pushed a commit that referenced this pull request Aug 15, 2024
* Integrate KNNVectorValues with vector ANN Search flow (#1952)

Signed-off-by: Navneet Verma <[email protected]>

* BackPort Java Doc Fix with Code Improvements (#1959)

* Quantization Framework Code Structure Improvement (#1967)

* BackPort Java Doc Fix with Code Improvements

Signed-off-by: VIKASH TIWARI <[email protected]>

* Quantization Framework Code Structure Improvement

Signed-off-by: VIKASH TIWARI <[email protected]>

---------

Signed-off-by: VIKASH TIWARI <[email protected]>

* Iterative index integration (#1956)

* Iterative Vector Insertion (#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Navneet Verma <[email protected]>
Signed-off-by: VIKASH TIWARI <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Navneet Verma <[email protected]>
Co-authored-by: Vikasht34 <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
shatejas added a commit to shatejas/k-NN that referenced this pull request Aug 15, 2024
* Iterative Vector Insertion (opensearch-project#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (opensearch-project#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
ryanbogan pushed a commit that referenced this pull request Aug 15, 2024
* Integrate KNNVectorValues with vector ANN Search flow (#1952)

Signed-off-by: Navneet Verma <[email protected]>

* Iterative index integration (#1956)

* Iterative Vector Insertion (#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Navneet Verma <[email protected]>
Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Navneet Verma <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 15, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 17, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
shatejas pushed a commit to shatejas/k-NN that referenced this pull request Aug 20, 2024
* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
ryanbogan pushed a commit that referenced this pull request Aug 20, 2024
…at (#1950)

* Iterative Vector Insertion (#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
shatejas added a commit to shatejas/k-NN that referenced this pull request Aug 20, 2024
…at (opensearch-project#1950)

* Iterative Vector Insertion (opensearch-project#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (opensearch-project#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
(cherry picked from commit fd59b9a)
navneet1v pushed a commit that referenced this pull request Aug 22, 2024
…at (#1950) (#1992)

* Iterative Vector Insertion (#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
(cherry picked from commit fd59b9a)

Signed-off-by: Tejas Shah <[email protected]>
akashsha1 pushed a commit to akashsha1/k-NN that referenced this pull request Sep 16, 2024
…at (opensearch-project#1950)

* Iterative Vector Insertion (opensearch-project#1840)

* Rebased with new version of k-NN

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized faiss insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Optimized threadCount logic

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed IDEA files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary cmake file

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to new functions

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex and fixed test cases that use it

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused code

Signed-off-by: Andrew Klepchick <[email protected]>

* Explained zero initialization for vector transfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Added locale

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless Apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Account for zero documents in finished batch

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed where we check for zero docs

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed tip for return

Signed-off-by: Andrew Klepchick <[email protected]>

* Use unique pointers to make sure resources are released on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Moved createIndex to testUtils

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management so that the underlying index is not deleted after initialized

Signed-off-by: Andrew Klepchick <[email protected]>

* Created new KNNIndexBuilder graph to make index building more modular

Signed-off-by: Andrew Klepchick <[email protected]>

* Streamlined logic in KNNIndexBuilder.

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up unnecessary code in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed memory management process

Signed-off-by: Andrew Klepchick <[email protected]>

* Added note about index initialization in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for case where the exception happens after the indexWriter is released.

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/modules.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/vcs.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Delete jni/src/.idea/workspace.xml

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply and free iterative index on exception

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid hack for checking first document metrics

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Free Vector Transfer on batch ingestion

Signed-off-by: Andrew Klepchick <[email protected]>

* Undid free

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed check for transfer ready

Signed-off-by: Andrew Klepchick <[email protected]>

* Don't crash when zero vectors inserted?

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted to old insertion process?

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed prior createOutput

Signed-off-by: Andrew Klepchick <[email protected]>

* Test remaking vectorTransfer

Signed-off-by: Andrew Klepchick <[email protected]>

* Test restructuring of insertion

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed case where vector address is immediately discarded

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Split Index Builder into multiple classes

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed descriptions of functions in faiss_index_service

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back copyright files

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unused builder names

Signed-off-by: Andrew Klepchick <[email protected]>

* Modified tests to work with new insertion methods

Signed-off-by: Andrew Klepchick <[email protected]>

* Track index insertions

Signed-off-by: Andrew Klepchick <[email protected]>

* Tracked insertions for binary indices

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back insertIds

Signed-off-by: Andrew Klepchick <[email protected]>

* Added check for freeVectorData to see if it works with an already deleted address

Signed-off-by: Andrew Klepchick <[email protected]>

* Cleaned up logs and comments in KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Restructured the logic for KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed package name of KNNIndexBuilder

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed all package names and deleted unnecessary headers

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed for loop

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed createIndex methods for faiss index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed package to fit naming conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name of index builder

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Added comments to NativeIndexBuilder and restructured

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion for memoryAddress

Signed-off-by: Andrew Klepchick <[email protected]>

* Spotless apply

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed naming of classes to Writer and changed package name to fit conventions

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed NativeIndexInfo and NativeVectorInfo to follow builder pattern

Signed-off-by: Andrew Klepchick <[email protected]>

* Added feature to changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Added class descriptions to each NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed name to getBytesPerVector

Signed-off-by: Andrew Klepchick <[email protected]>

* Added == false instead of ! for readability

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming in docvaluesconsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* SpotlessApply

Signed-off-by: Andrew Klepchick <[email protected]>

* Made it so that we don't reuse testValues and removed a foot gun

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed another foot gun in getIndexInfo

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Added deletion on exception cases

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary delete (NativeIndexWriter will handle deletion of vectors on exception)

Signed-off-by: Andrew Klepchick <[email protected]>

* Added correct logger and getWriter method to NativeIndexWriter

Signed-off-by: Andrew Klepchick <[email protected]>

* Ensured memory safety on JNI layer so that Java doesn't have to wrap everything in a try catch loop.

Signed-off-by: Andrew Klepchick <[email protected]>

* Refactored NativeIndexWriter and added comments to FaissService

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed free in the JNIExport since index will always be freed in writeIndex.

Signed-off-by: Andrew Klepchick <[email protected]>

* Changed getVectorTransfer back to accept VectorDataType

Signed-off-by: Andrew Klepchick <[email protected]>

* Reverted free since not guaranteed to be IDMap.

Signed-off-by: Andrew Klepchick <[email protected]>

* Added all processes in addKNNBinaryField to NativeIndexWriter.createKNNIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed javadoc

Signed-off-by: Andrew Klepchick <[email protected]>

* Applied spotless

Signed-off-by: Andrew Klepchick <[email protected]>

* Added back writeFooter

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed threadCount fron writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed redundancies in KNN80DocValuesConsumer

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed serializationMode

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed double free test as we don't have to worry about that anymore

Signed-off-by: Andrew Klepchick <[email protected]>

* Accounted for HNSWSQ in index service

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed delete in catch

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed faiss tests to work with writeIndex

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Index Initialization Alloc Method (opensearch-project#1933)

* Added methods for allocating memory before inserting vectors to a faiss index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed logic that gets type of index

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statement

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary iostream

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed flat index

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed flat index case

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed naming

Signed-off-by: Andrew Klepchick <[email protected]>

* Properly allocate HNSWSQ storage

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed print statements

Signed-off-by: Andrew Klepchick <[email protected]>

* Fixed changelog

Signed-off-by: Andrew Klepchick <[email protected]>

* Removed unnecessary lib

Signed-off-by: Andrew Klepchick <[email protected]>

* Made alloc adaptive to different code sizes

Signed-off-by: Andrew Klepchick <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>

* Integrates FAISS iterative builds with NativeEngines990KnnVectorsFormat

Changes include reusing the same vector buffer in the JNI layer

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Andrew Klepchick <[email protected]>
Signed-off-by: Tejas Shah <[email protected]>
Co-authored-by: Andrew Klepchick <[email protected]>
Signed-off-by: Akash Shankaran <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancements Increases software capabilities beyond original client specifications indexing-improvements This label should be attached to all the github issues which will help improving the indexing time. v2.17.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants