├── .gitattributes
├── .github
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── .gitmodules
├── AnnService.users.props
├── AnnService
├── Aggregator.vcxproj
├── Aggregator.vcxproj.filters
├── BalancedDataPartition.vcxproj
├── BalancedDataPartition.vcxproj.filters
├── CMakeLists.txt
├── Client.vcxproj
├── Client.vcxproj.filters
├── CoreLibrary.vcxproj
├── CoreLibrary.vcxproj.filters
├── GPUCoreLibrary.vcxproj
├── GPUCoreLibrary.vcxproj.filters
├── GPUIndexBuilder.vcxproj
├── GPUIndexBuilder.vcxproj.filters
├── GPUSSDServing.vcxproj
├── GPUSSDServing.vcxproj.filters
├── IndexBuilder.vcxproj
├── IndexBuilder.vcxproj.filters
├── IndexSearcher.vcxproj
├── IndexSearcher.vcxproj.filters
├── Quantizer.vcxproj
├── Quantizer.vcxproj.filters
├── SSDServing.vcxproj
├── SSDServing.vcxproj.filters
├── Server.vcxproj
├── Server.vcxproj.filters
├── SocketLib.vcxproj
├── SocketLib.vcxproj.filters
├── inc
│ ├── Aggregator
│ │ ├── AggregatorContext.h
│ │ ├── AggregatorExecutionContext.h
│ │ ├── AggregatorService.h
│ │ └── AggregatorSettings.h
│ ├── Client
│ │ ├── ClientWrapper.h
│ │ └── Options.h
│ ├── Core
│ │ ├── BKT
│ │ │ ├── Index.h
│ │ │ └── ParameterDefinitionList.h
│ │ ├── Common.h
│ │ ├── Common
│ │ │ ├── BKTree.h
│ │ │ ├── CommonUtils.h
│ │ │ ├── Dataset.h
│ │ │ ├── DistanceUtils.h
│ │ │ ├── FineGrainedLock.h
│ │ │ ├── Heap.h
│ │ │ ├── IQuantizer.h
│ │ │ ├── InstructionUtils.h
│ │ │ ├── KDTree.h
│ │ │ ├── KNearestNeighborhoodGraph.h
│ │ │ ├── Labelset.h
│ │ │ ├── NeighborhoodGraph.h
│ │ │ ├── OPQQuantizer.h
│ │ │ ├── PQQuantizer.h
│ │ │ ├── QueryResultSet.h
│ │ │ ├── RelativeNeighborhoodGraph.h
│ │ │ ├── SIMDUtils.h
│ │ │ ├── TruthSet.h
│ │ │ ├── WorkSpace.h
│ │ │ ├── WorkSpacePool.h
│ │ │ └── cuda
│ │ │ │ ├── Distance.hxx
│ │ │ │ ├── GPUKNNDistance.hxx
│ │ │ │ ├── GPUQuantizer.hxx
│ │ │ │ ├── KNN.hxx
│ │ │ │ ├── Kmeans.hxx
│ │ │ │ ├── PerfTestGPU.hxx
│ │ │ │ ├── Refine.hxx
│ │ │ │ ├── TPtree.hxx
│ │ │ │ ├── TailNeighbors.hxx
│ │ │ │ ├── ThreadHeap.hxx
│ │ │ │ ├── log.hxx
│ │ │ │ └── params.h
│ │ ├── CommonDataStructure.h
│ │ ├── DefinitionList.h
│ │ ├── KDT
│ │ │ ├── Index.h
│ │ │ └── ParameterDefinitionList.h
│ │ ├── MetadataSet.h
│ │ ├── MultiIndexScan.h
│ │ ├── ResultIterator.h
│ │ ├── SPANN
│ │ │ ├── Compressor.h
│ │ │ ├── ExtraFullGraphSearcher.h
│ │ │ ├── IExtraSearcher.h
│ │ │ ├── Index.h
│ │ │ ├── Options.h
│ │ │ ├── ParameterDefinitionList.h
│ │ │ └── SPANNResultIterator.h
│ │ ├── SearchQuery.h
│ │ ├── SearchResult.h
│ │ ├── VectorIndex.h
│ │ └── VectorSet.h
│ ├── Helper
│ │ ├── ArgumentsParser.h
│ │ ├── AsyncFileReader.h
│ │ ├── Base64Encode.h
│ │ ├── CommonHelper.h
│ │ ├── Concurrent.h
│ │ ├── ConcurrentSet.h
│ │ ├── DiskIO.h
│ │ ├── DynamicNeighbors.h
│ │ ├── LockFree.h
│ │ ├── Logging.h
│ │ ├── SimpleIniReader.h
│ │ ├── StringConvert.h
│ │ ├── ThreadPool.h
│ │ ├── VectorSetReader.h
│ │ └── VectorSetReaders
│ │ │ ├── DefaultReader.h
│ │ │ ├── MemoryReader.h
│ │ │ ├── TxtReader.h
│ │ │ └── XvecReader.h
│ ├── Quantizer
│ │ └── Training.h
│ ├── SSDServing
│ │ ├── SSDIndex.h
│ │ ├── SelectHead.h
│ │ ├── Utils.h
│ │ └── main.h
│ ├── Server
│ │ ├── QueryParser.h
│ │ ├── SearchExecutionContext.h
│ │ ├── SearchExecutor.h
│ │ ├── SearchService.h
│ │ ├── ServiceContext.h
│ │ └── ServiceSettings.h
│ └── Socket
│ │ ├── Client.h
│ │ ├── Common.h
│ │ ├── Connection.h
│ │ ├── ConnectionManager.h
│ │ ├── Packet.h
│ │ ├── RemoteSearchQuery.h
│ │ ├── ResourceManager.h
│ │ ├── Server.h
│ │ └── SimpleSerialization.h
├── packages.config
└── src
│ ├── Aggregator
│ ├── AggregatorContext.cpp
│ ├── AggregatorExecutionContext.cpp
│ ├── AggregatorService.cpp
│ ├── AggregatorSettings.cpp
│ └── main.cpp
│ ├── BalancedDataPartition
│ └── main.cpp
│ ├── Client
│ ├── ClientWrapper.cpp
│ ├── Options.cpp
│ └── main.cpp
│ ├── Core
│ ├── BKT
│ │ └── BKTIndex.cpp
│ ├── Common
│ │ ├── CommonUtils.cpp
│ │ ├── DistanceUtils.cpp
│ │ ├── IQuantizer.cpp
│ │ ├── InstructionUtils.cpp
│ │ ├── Kernel.cu
│ │ ├── NeighborhoodGraph.cpp
│ │ ├── SIMDUtils.cpp
│ │ └── TruthSet.cpp
│ ├── KDT
│ │ └── KDTIndex.cpp
│ ├── MetadataSet.cpp
│ ├── MultiIndexScan.cpp
│ ├── ResultIterator.cpp
│ ├── SPANN
│ │ └── SPANNIndex.cpp
│ ├── SPANNResultIterator.cpp
│ ├── VectorIndex.cpp
│ └── VectorSet.cpp
│ ├── Helper
│ ├── ArgumentsParser.cpp
│ ├── AsyncFileReader.cpp
│ ├── Base64Encode.cpp
│ ├── CommonHelper.cpp
│ ├── Concurrent.cpp
│ ├── DynamicNeighbors.cpp
│ ├── SimpleIniReader.cpp
│ ├── VectorSetReader.cpp
│ └── VectorSetReaders
│ │ ├── DefaultReader.cpp
│ │ ├── TxtReader.cpp
│ │ └── XvecReader.cpp
│ ├── IndexBuilder
│ └── main.cpp
│ ├── IndexSearcher
│ └── main.cpp
│ ├── Quantizer
│ └── main.cpp
│ ├── SSDServing
│ └── main.cpp
│ ├── Server
│ ├── QueryParser.cpp
│ ├── SearchExecutionContext.cpp
│ ├── SearchExecutor.cpp
│ ├── SearchService.cpp
│ ├── ServiceContext.cpp
│ ├── ServiceSettings.cpp
│ └── main.cpp
│ └── Socket
│ ├── Client.cpp
│ ├── Common.cpp
│ ├── Connection.cpp
│ ├── ConnectionManager.cpp
│ ├── Packet.cpp
│ ├── RemoteSearchQuery.cpp
│ └── Server.cpp
├── CMakeLists.txt
├── Dockerfile
├── Dockerfile.cuda
├── GPUSupport
└── CMakeLists.txt
├── LICENSE
├── MANIFEST.in
├── README.md
├── SECURITY.md
├── SPTAG.WinRT.nuspec
├── SPTAG.nuspec
├── SPTAG.sdf
├── SPTAG.sln
├── SPTAG.targets
├── Test
├── CMakeLists.txt
├── Test.vcxproj
├── Test.vcxproj.filters
├── WinRTTest
│ ├── WinRTTest.cpp
│ ├── WinRTTest.vcxproj
│ ├── WinRTTest.vcxproj.filters
│ └── packages.config
├── cuda
│ ├── buildssd_test.cu
│ ├── common.hxx
│ ├── cuda_tests.cpp
│ ├── distance_tests.cu
│ ├── gpu_pq_perf.cu
│ ├── knn_tests.cu
│ ├── pq_perf.cpp
│ └── tptree_tests.cu
├── inc
│ └── Test.h
├── packages.config
└── src
│ ├── AlgoTest.cpp
│ ├── Base64HelperTest.cpp
│ ├── CommonHelperTest.cpp
│ ├── ConcurrentTest.cpp
│ ├── DistanceTest.cpp
│ ├── FilterTest.cpp
│ ├── IniReaderTest.cpp
│ ├── IterativeScanTest.cpp
│ ├── MultiIndexExperiment.cpp
│ ├── MultiIndexScanTest.cpp
│ ├── PerfTest.cpp
│ ├── ReconstructIndexSimilarityTest.cpp
│ ├── SIMDTest.cpp
│ ├── SSDServingTest.cpp
│ ├── StringConvertTest.cpp
│ ├── main.cpp
│ └── make_gist_sptag.py
├── Tools
├── OPQ
│ ├── OPQ_gpu_train_infer.py
│ └── README.md
└── nni-auto-tune
│ ├── README.md
│ ├── config.yml
│ ├── config_aml.yml
│ ├── dataset.py
│ ├── main.py
│ ├── model.py
│ ├── picture
│ ├── fashion-mnist-784-euclidean.png
│ ├── glove-100-angular.png
│ ├── glove-25-angular.png
│ ├── nytimes-256-angular.png
│ └── sift-128-euclidean.png
│ ├── plot.py
│ ├── preprocessing.py
│ ├── runner.py
│ ├── search_space.json
│ └── search_space_small.json
├── Wrappers
├── CLRCore.vcxproj
├── CLRCore.vcxproj.filters
├── CMakeLists.txt
├── CsharpClient.vcxproj
├── CsharpClient.vcxproj.filters
├── CsharpCore.vcxproj
├── CsharpCore.vcxproj.filters
├── JavaClient.vcxproj
├── JavaClient.vcxproj.filters
├── JavaCore.vcxproj
├── JavaCore.vcxproj.filters
├── PythonClient.vcxproj
├── PythonClient.vcxproj.filters
├── PythonCore.vcxproj
├── PythonCore.vcxproj.filters
├── WinRT
│ ├── AnnIndex.cpp
│ ├── AnnIndex.h
│ ├── AnnIndex.idl
│ ├── PropertySheet.props
│ ├── SPTAG.WinRT.targets
│ ├── SPTAG.WinRT.vcxproj
│ ├── SPTAG.def
│ ├── packages.config
│ ├── pch.cpp
│ └── pch.h
├── inc
│ ├── CLRCoreInterface.h
│ ├── ClientInterface.h
│ ├── CoreInterface.h
│ ├── CsharpClient.i
│ ├── CsharpCommon.i
│ ├── CsharpCore.i
│ ├── JavaClient.i
│ ├── JavaCommon.i
│ ├── JavaCore.i
│ ├── ManagedObject.h
│ ├── PythonClient.i
│ ├── PythonCommon.i
│ ├── PythonCore.i
│ └── TransferDataType.h
├── packages.config
└── src
│ ├── AssemblyInfo.cpp
│ ├── CLRCoreInterface.cpp
│ ├── ClientInterface.cpp
│ └── CoreInterface.cpp
├── azure-pipelines.yml
├── datasets
└── SPACEV1B
│ ├── LICENSE
│ ├── README.md
│ ├── query.bin
│ ├── query_log.bin
│ ├── truth.bin
│ └── vectors.bin
│ ├── vectors_1.bin
│ ├── vectors_10.bin
│ ├── vectors_11.bin
│ ├── vectors_12.bin
│ ├── vectors_13.bin
│ ├── vectors_14.bin
│ ├── vectors_15.bin
│ ├── vectors_16.bin
│ ├── vectors_17.bin
│ ├── vectors_18.bin
│ ├── vectors_19.bin
│ ├── vectors_2.bin
│ ├── vectors_20.bin
│ ├── vectors_21.bin
│ ├── vectors_22.bin
│ ├── vectors_23.bin
│ ├── vectors_24.bin
│ ├── vectors_25.bin
│ ├── vectors_26.bin
│ ├── vectors_27.bin
│ ├── vectors_28.bin
│ ├── vectors_29.bin
│ ├── vectors_3.bin
│ ├── vectors_30.bin
│ ├── vectors_31.bin
│ ├── vectors_32.bin
│ ├── vectors_33.bin
│ ├── vectors_4.bin
│ ├── vectors_5.bin
│ ├── vectors_6.bin
│ ├── vectors_7.bin
│ ├── vectors_8.bin
│ └── vectors_9.bin
├── docs
├── GettingStart.md
├── LinuxInstallation.md
├── Parameters.md
├── Tutorial.ipynb
├── WindowsInstallation.md
├── examples
│ ├── QuickstartGuide.ipynb
│ ├── features_extractor.py
│ └── requirements.txt
└── img
│ ├── sptag.png
│ ├── swigpath.PNG
│ └── visualstudio.png
├── setup.py
└── setup.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.bin filter=lfs diff=lfs merge=lfs -text
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behavior:
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | **Expected behavior**
18 | A clear and concise description of what you expected to happen.
19 |
20 | **Screenshots**
21 | If applicable, add screenshots to help explain your problem.
22 |
23 | **Desktop (please complete the following information):**
24 | - OS: [e.g. iOS]
25 | - Browser [e.g. chrome, safari]
26 | - Version [e.g. 22]
27 |
28 | **Smartphone (please complete the following information):**
29 | - Device: [e.g. iPhone6]
30 | - OS: [e.g. iOS8.1]
31 | - Browser [e.g. stock browser, safari]
32 | - Version [e.g. 22]
33 |
34 | **Additional context**
35 | Add any other context about the problem here.
36 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9 |
10 | **Describe the solution you'd like**
11 | A clear and concise description of what you want to happen.
12 |
13 | **Describe alternatives you've considered**
14 | A clear and concise description of any alternative solutions or features you've considered.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ThirdParty/zstd"]
2 | path = ThirdParty/zstd
3 | url = https://github.com/facebook/zstd
4 | branch = release
5 |
--------------------------------------------------------------------------------
/AnnService.users.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | $(SystemVersionDef) %(AdditionalOptions)
8 |
9 |
10 |
11 |
12 | $(SolutionDir)\$(Platform)\$(Configuration)\
13 | $(SolutionDir)\$(Platform)\$(Configuration)\
14 |
15 |
16 | 3.9
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/AnnService/Aggregator.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 |
14 |
15 | Header Files
16 |
17 |
18 | Header Files
19 |
20 |
21 | Header Files
22 |
23 |
24 | Header Files
25 |
26 |
27 |
28 |
29 | Source Files
30 |
31 |
32 | Source Files
33 |
34 |
35 | Source Files
36 |
37 |
38 | Source Files
39 |
40 |
41 | Source Files
42 |
43 |
44 | Source Files
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/AnnService/BalancedDataPartition.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Source Files
23 |
24 |
25 |
--------------------------------------------------------------------------------
/AnnService/Client.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 |
14 |
15 | Source Files
16 |
17 |
18 | Source Files
19 |
20 |
21 | Source Files
22 |
23 |
24 |
25 |
26 | Header Files
27 |
28 |
29 | Header Files
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/AnnService/GPUIndexBuilder.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {c260e4c4-ec44-4d50-941f-078454da2a89}
6 |
7 |
8 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
9 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
10 |
11 |
12 |
13 |
14 | Source Files
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/AnnService/GPUSSDServing.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {5bf17d80-3c16-4aef-918c-6994296bb320}
6 |
7 |
8 | {edefc9a5-628e-4695-aaad-22951d646b18}
9 |
10 |
11 |
12 |
13 | Header Files
14 |
15 |
16 | Header Files
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/AnnService/IndexBuilder.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 |
14 |
15 | Source Files
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/AnnService/IndexSearcher.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/AnnService/Quantizer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/AnnService/SSDServing.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {d5aba8fd-7ec7-458a-b728-ae5eaea04e43}
6 |
7 |
8 | {6835b7a3-6818-4a89-89c0-fc6527dbf613}
9 |
10 |
11 |
12 |
13 | Header Files
14 |
15 |
16 | Header Files
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 |
26 |
27 | Source Files
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/AnnService/Server.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 |
14 |
15 | Header Files
16 |
17 |
18 | Header Files
19 |
20 |
21 | Header Files
22 |
23 |
24 | Header Files
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 |
34 |
35 | Source Files
36 |
37 |
38 | Source Files
39 |
40 |
41 | Source Files
42 |
43 |
44 | Source Files
45 |
46 |
47 | Source Files
48 |
49 |
50 | Source Files
51 |
52 |
53 | Source Files
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/AnnService/SocketLib.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 |
14 |
15 | Header Files
16 |
17 |
18 | Header Files
19 |
20 |
21 | Header Files
22 |
23 |
24 | Header Files
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 |
43 |
44 | Source Files
45 |
46 |
47 | Source Files
48 |
49 |
50 | Source Files
51 |
52 |
53 | Source Files
54 |
55 |
56 | Source Files
57 |
58 |
59 | Source Files
60 |
61 |
62 | Source Files
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/AnnService/inc/Aggregator/AggregatorContext.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_AGGREGATOR_AGGREGATORCONTEXT_H_
5 | #define _SPTAG_AGGREGATOR_AGGREGATORCONTEXT_H_
6 |
7 | #include "inc/Socket/Common.h"
8 | #include "inc/Core/VectorSet.h"
9 | #include "AggregatorSettings.h"
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | namespace SPTAG
16 | {
17 | namespace Aggregator
18 | {
19 |
20 | enum RemoteMachineStatus : uint8_t
21 | {
22 | Disconnected = 0,
23 |
24 | Connecting,
25 |
26 | Connected
27 | };
28 |
29 |
30 | struct RemoteMachine
31 | {
32 | RemoteMachine();
33 |
34 | std::string m_address;
35 |
36 | std::string m_port;
37 |
38 | Socket::ConnectionID m_connectionID;
39 |
40 | std::atomic m_status;
41 | };
42 |
43 | class AggregatorContext
44 | {
45 | public:
46 | AggregatorContext(const std::string& p_filePath);
47 |
48 | ~AggregatorContext();
49 |
50 | bool IsInitialized() const;
51 |
52 | const std::vector>& GetRemoteServers() const;
53 |
54 | const std::shared_ptr& GetSettings() const;
55 |
56 | const std::shared_ptr& GetCenters() const;
57 |
58 | private:
59 | std::vector> m_remoteServers;
60 |
61 | std::shared_ptr m_centers;
62 |
63 | std::shared_ptr m_settings;
64 |
65 | bool m_initialized;
66 | };
67 |
68 | } // namespace Aggregator
69 | } // namespace AnnService
70 |
71 |
72 | #endif // _SPTAG_AGGREGATOR_AGGREGATORCONTEXT_H_
73 |
--------------------------------------------------------------------------------
/AnnService/inc/Aggregator/AggregatorExecutionContext.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_AGGREGATOR_AGGREGATOREXECUTIONCONTEXT_H_
5 | #define _SPTAG_AGGREGATOR_AGGREGATOREXECUTIONCONTEXT_H_
6 |
7 | #include "inc/Socket/RemoteSearchQuery.h"
8 | #include "inc/Socket/Packet.h"
9 |
10 | #include
11 | #include
12 |
13 | namespace SPTAG
14 | {
15 | namespace Aggregator
16 | {
17 |
18 | typedef std::shared_ptr AggregatorResult;
19 |
20 | class AggregatorExecutionContext
21 | {
22 | public:
23 | AggregatorExecutionContext(std::size_t p_totalServerNumber,
24 | Socket::PacketHeader p_requestHeader);
25 |
26 | ~AggregatorExecutionContext();
27 |
28 | std::size_t GetServerNumber() const;
29 |
30 | AggregatorResult& GetResult(std::size_t p_num);
31 |
32 | const Socket::PacketHeader& GetRequestHeader() const;
33 |
34 | bool IsCompletedAfterFinsh(std::uint32_t p_finishedCount);
35 |
36 | private:
37 | std::atomic m_unfinishedCount;
38 |
39 | std::vector m_results;
40 |
41 | Socket::PacketHeader m_requestHeader;
42 |
43 | };
44 |
45 |
46 |
47 |
48 | } // namespace Aggregator
49 | } // namespace AnnService
50 |
51 |
52 | #endif // _SPTAG_AGGREGATOR_AGGREGATOREXECUTIONCONTEXT_H_
53 |
54 |
--------------------------------------------------------------------------------
/AnnService/inc/Aggregator/AggregatorService.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_AGGREGATOR_AGGREGATORSERVICE_H_
5 | #define _SPTAG_AGGREGATOR_AGGREGATORSERVICE_H_
6 |
7 | #include "AggregatorContext.h"
8 | #include "AggregatorExecutionContext.h"
9 | #include "inc/Socket/Server.h"
10 | #include "inc/Socket/Client.h"
11 | #include "inc/Socket/ResourceManager.h"
12 |
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | namespace SPTAG
21 | {
22 | namespace Aggregator
23 | {
24 |
25 | class AggregatorService
26 | {
27 | public:
28 | AggregatorService();
29 |
30 | ~AggregatorService();
31 |
32 | bool Initialize();
33 |
34 | void Run();
35 |
36 | private:
37 |
38 | void StartClient();
39 |
40 | void StartListen();
41 |
42 | void WaitForShutdown();
43 |
44 | void ConnectToPendingServers();
45 |
46 | void AddToPendingServers(std::shared_ptr p_remoteServer);
47 |
48 | void SearchRequestHanlder(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);
49 |
50 | void SearchResponseHanlder(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);
51 |
52 | void AggregateResults(std::shared_ptr p_exectionContext);
53 |
54 | std::shared_ptr GetContext();
55 |
56 | private:
57 | typedef std::function AggregatorCallback;
58 |
59 | std::shared_ptr m_aggregatorContext;
60 |
61 | std::shared_ptr m_socketServer;
62 |
63 | std::shared_ptr m_socketClient;
64 |
65 | bool m_initalized;
66 |
67 | std::unique_ptr m_threadPool;
68 |
69 | boost::asio::io_context m_ioContext;
70 |
71 | boost::asio::signal_set m_shutdownSignals;
72 |
73 | std::vector> m_pendingConnectServers;
74 |
75 | std::mutex m_pendingConnectServersMutex;
76 |
77 | boost::asio::deadline_timer m_pendingConnectServersTimer;
78 |
79 | Socket::ResourceManager m_aggregatorCallbackManager;
80 | };
81 |
82 |
83 |
84 | } // namespace Aggregator
85 | } // namespace AnnService
86 |
87 |
88 | #endif // _SPTAG_AGGREGATOR_AGGREGATORSERVICE_H_
89 |
--------------------------------------------------------------------------------
/AnnService/inc/Aggregator/AggregatorSettings.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_AGGREGATOR_AGGREGATORSETTINGS_H_
5 | #define _SPTAG_AGGREGATOR_AGGREGATORSETTINGS_H_
6 |
7 | #include "../Core/Common.h"
8 |
9 | #include
10 |
11 | namespace SPTAG
12 | {
13 | namespace Aggregator
14 | {
15 |
16 | struct AggregatorSettings
17 | {
18 | AggregatorSettings();
19 |
20 | std::string m_listenAddr;
21 |
22 | std::string m_listenPort;
23 |
24 | std::uint32_t m_searchTimeout;
25 |
26 | SizeType m_threadNum;
27 |
28 | SizeType m_socketThreadNum;
29 |
30 | std::string m_centers;
31 |
32 | VectorValueType m_valueType;
33 |
34 | SizeType m_topK;
35 |
36 | DistCalcMethod m_distMethod;
37 | };
38 |
39 |
40 |
41 |
42 | } // namespace Aggregator
43 | } // namespace AnnService
44 |
45 |
46 | #endif // _SPTAG_AGGREGATOR_AGGREGATORSETTINGS_H_
47 |
48 |
--------------------------------------------------------------------------------
/AnnService/inc/Client/ClientWrapper.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_CLIENT_CLIENTWRAPPER_H_
5 | #define _SPTAG_CLIENT_CLIENTWRAPPER_H_
6 |
7 | #include "inc/Socket/Client.h"
8 | #include "inc/Socket/RemoteSearchQuery.h"
9 | #include "inc/Socket/ResourceManager.h"
10 | #include "Options.h"
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | namespace SPTAG
22 | {
23 | namespace Client
24 | {
25 |
26 | class ClientWrapper
27 | {
28 | public:
29 | typedef std::function Callback;
30 |
31 | ClientWrapper(const ClientOptions& p_options);
32 |
33 | ~ClientWrapper();
34 |
35 | void SendQueryAsync(const Socket::RemoteQuery& p_query,
36 | Callback p_callback,
37 | const ClientOptions& p_options);
38 |
39 | void WaitAllFinished();
40 |
41 | bool IsAvailable() const;
42 |
43 | private:
44 | typedef std::pair ConnectionPair;
45 |
46 | Socket::PacketHandlerMapPtr GetHandlerMap();
47 |
48 | void DecreaseUnfnishedJobCount();
49 |
50 | const ConnectionPair& GetConnection();
51 |
52 | void SearchResponseHanlder(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);
53 |
54 | void HandleDeadConnection(Socket::ConnectionID p_cid);
55 |
56 | private:
57 | ClientOptions m_options;
58 |
59 | std::unique_ptr m_client;
60 |
61 | std::atomic m_unfinishedJobCount;
62 |
63 | std::atomic_bool m_isWaitingFinish;
64 |
65 | std::condition_variable m_waitingQueue;
66 |
67 | std::mutex m_waitingMutex;
68 |
69 | std::vector m_connections;
70 |
71 | std::atomic m_spinCountOfConnection;
72 |
73 | Socket::ResourceManager m_callbackManager;
74 | };
75 |
76 |
77 | } // namespace Socket
78 | } // namespace SPTAG
79 |
80 | #endif // _SPTAG_CLIENT_OPTIONS_H_
81 |
--------------------------------------------------------------------------------
/AnnService/inc/Client/Options.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_CLIENT_OPTIONS_H_
5 | #define _SPTAG_CLIENT_OPTIONS_H_
6 |
7 | #include "inc/Helper/ArgumentsParser.h"
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | namespace SPTAG
14 | {
15 | namespace Client
16 | {
17 |
18 | class ClientOptions : public Helper::ArgumentsParser
19 | {
20 | public:
21 | ClientOptions();
22 |
23 | virtual ~ClientOptions();
24 |
25 | std::string m_serverAddr;
26 |
27 | std::string m_serverPort;
28 |
29 | // in milliseconds.
30 | std::uint32_t m_searchTimeout;
31 |
32 | std::uint32_t m_threadNum;
33 |
34 | std::uint32_t m_socketThreadNum;
35 |
36 | };
37 |
38 |
39 | } // namespace Socket
40 | } // namespace SPTAG
41 |
42 | #endif // _SPTAG_CLIENT_OPTIONS_H_
43 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/FineGrainedLock.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_COMMON_FINEGRAINEDLOCK_H_
5 | #define _SPTAG_COMMON_FINEGRAINEDLOCK_H_
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | namespace SPTAG
13 | {
14 | namespace COMMON
15 | {
16 | class FineGrainedLock {
17 | public:
18 | FineGrainedLock() {
19 | m_locks.reset(new std::mutex[PoolSize + 1]);
20 | }
21 | ~FineGrainedLock() {}
22 |
23 | std::mutex& operator[](SizeType idx) {
24 | unsigned index = hash_func((unsigned)idx);
25 | return m_locks[index];
26 | }
27 |
28 | const std::mutex& operator[](SizeType idx) const {
29 | unsigned index = hash_func((unsigned)idx);
30 | return m_locks[index];
31 | }
32 | private:
33 | static const int PoolSize = 32767;
34 | std::unique_ptr m_locks;
35 |
36 | inline unsigned hash_func(unsigned idx) const
37 | {
38 | return ((unsigned)(idx * 99991) + _rotl(idx, 2) + 101) & PoolSize;
39 | }
40 | };
41 | }
42 | }
43 |
44 | #endif // _SPTAG_COMMON_FINEGRAINEDLOCK_H_
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/IQuantizer.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_COMMON_QUANTIZER_H_
5 | #define _SPTAG_COMMON_QUANTIZER_H_
6 |
7 | #include "inc/Core/Common.h"
8 | #include
9 | #include "inc/Core/CommonDataStructure.h"
10 | #include "DistanceUtils.h"
11 |
12 | namespace SPTAG
13 | {
14 | namespace COMMON
15 | {
16 | class IQuantizer
17 | {
18 | public:
19 | virtual float L2Distance(const std::uint8_t* pX, const std::uint8_t* pY) const = 0;
20 |
21 | virtual float CosineDistance(const std::uint8_t* pX, const std::uint8_t* pY) const = 0;
22 |
23 | template
24 | std::function DistanceCalcSelector(SPTAG::DistCalcMethod p_method) const;
25 |
26 | virtual void QuantizeVector(const void* vec, std::uint8_t* vecout, bool ADC = true) const = 0;
27 |
28 | virtual SizeType QuantizeSize() const = 0;
29 |
30 | virtual void ReconstructVector(const std::uint8_t* qvec, void* vecout) const = 0;
31 |
32 | virtual SizeType ReconstructSize() const = 0;
33 |
34 | virtual DimensionType ReconstructDim() const = 0;
35 |
36 | virtual std::uint64_t BufferSize() const = 0;
37 |
38 | virtual ErrorCode SaveQuantizer(std::shared_ptr p_out) const = 0;
39 |
40 | virtual ErrorCode LoadQuantizer(std::shared_ptr p_in) = 0;
41 |
42 | virtual ErrorCode LoadQuantizer(uint8_t* raw_bytes) = 0;
43 |
44 | static std::shared_ptr LoadIQuantizer(std::shared_ptr p_in);
45 |
46 | static std::shared_ptr LoadIQuantizer(SPTAG::ByteArray bytes);
47 |
48 | virtual bool GetEnableADC() const = 0;
49 |
50 | virtual void SetEnableADC(bool enableADC) = 0;
51 |
52 | virtual QuantizerType GetQuantizerType() const = 0;
53 |
54 | virtual VectorValueType GetReconstructType() const = 0;
55 |
56 | virtual DimensionType GetNumSubvectors() const = 0;
57 |
58 | virtual int GetBase() const = 0;
59 |
60 | virtual float* GetL2DistanceTables() = 0;
61 |
62 | template
63 | T* GetCodebooks();
64 | };
65 | }
66 | }
67 |
68 | #endif // _SPTAG_COMMON_QUANTIZER_H_
69 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/InstructionUtils.h:
--------------------------------------------------------------------------------
1 | #ifndef _SPTAG_COMMON_INSTRUCTIONUTILS_H_
2 | #define _SPTAG_COMMON_INSTRUCTIONUTILS_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #ifndef GPU
10 |
11 | #ifndef _MSC_VER
12 | #include
13 | #include
14 | #include
15 |
16 | void cpuid(int info[4], int InfoType);
17 |
18 | #else
19 | #include
20 | #define cpuid(info, x) __cpuidex(info, x, 0)
21 | #endif
22 |
23 | #endif
24 |
25 | namespace SPTAG {
26 | namespace COMMON {
27 |
28 | class InstructionSet
29 | {
30 | // forward declarations
31 | class InstructionSet_Internal;
32 |
33 | public:
34 | // getters
35 | static bool AVX(void);
36 | static bool SSE(void);
37 | static bool SSE2(void);
38 | static bool AVX2(void);
39 | static bool AVX512(void);
40 | static void PrintInstructionSet(void);
41 |
42 | private:
43 | static const InstructionSet_Internal CPU_Rep;
44 |
45 | class InstructionSet_Internal
46 | {
47 | public:
48 | InstructionSet_Internal();
49 | bool HW_SSE;
50 | bool HW_SSE2;
51 | bool HW_AVX;
52 | bool HW_AVX2;
53 | bool HW_AVX512;
54 | };
55 | };
56 | }
57 | }
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/KNearestNeighborhoodGraph.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_COMMON_KNG_H_
5 | #define _SPTAG_COMMON_KNG_H_
6 |
7 | #include "NeighborhoodGraph.h"
8 |
9 | namespace SPTAG
10 | {
11 | namespace COMMON
12 | {
13 | class KNearestNeighborhoodGraph : public NeighborhoodGraph
14 | {
15 | public:
16 | KNearestNeighborhoodGraph() { m_pNeighborhoodGraph.SetName("NNG"); }
17 |
18 | void RebuildNeighbors(VectorIndex* index, const SizeType node, SizeType* nodes, const BasicResult* queryResults, const int numResults) {
19 | DimensionType count = 0;
20 | for (int j = 0; j < numResults && count < m_iNeighborhoodSize; j++) {
21 | const BasicResult& item = queryResults[j];
22 | if (item.VID < 0) break;
23 | if (item.VID == node) continue;
24 | nodes[count++] = item.VID;
25 | }
26 | for (DimensionType j = count; j < m_iNeighborhoodSize; j++) nodes[j] = -1;
27 | }
28 |
29 | void InsertNeighbors(VectorIndex* index, const SizeType node, SizeType insertNode, float insertDist)
30 | {
31 | std::lock_guard lock(m_dataUpdateLock[node]);
32 |
33 | SizeType* nodes = m_pNeighborhoodGraph[node];
34 | SizeType tmpNode;
35 | float tmpDist;
36 | for (DimensionType k = 0; k < m_iNeighborhoodSize; k++)
37 | {
38 | tmpNode = nodes[k];
39 | if (tmpNode < -1) break;
40 |
41 | if (tmpNode < 0 || (tmpDist = index->ComputeDistance(index->GetSample(node), index->GetSample(tmpNode))) > insertDist
42 | || (insertDist == tmpDist && insertNode < tmpNode))
43 | {
44 | nodes[k] = insertNode;
45 | while (tmpNode >= 0 && ++k < m_iNeighborhoodSize && nodes[k] >= -1)
46 | {
47 | std::swap(tmpNode, nodes[k]);
48 | }
49 | break;
50 | }
51 | }
52 | }
53 | };
54 | }
55 | }
56 | #endif
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/SIMDUtils.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_COMMON_SIMDUTILS_H_
5 | #define _SPTAG_COMMON_SIMDUTILS_H_
6 |
7 | #include
8 | #include
9 |
10 | #include "CommonUtils.h"
11 | #include "InstructionUtils.h"
12 |
13 | namespace SPTAG
14 | {
15 | namespace COMMON
16 | {
17 | template
18 | using SumCalcReturn = void(*)(T*, const T*, DimensionType);
19 | template
20 | inline SumCalcReturn SumCalcSelector();
21 |
22 | class SIMDUtils
23 | {
24 | public:
25 | template
26 | static void ComputeSum_Naive(T* pX, const T* pY, DimensionType length)
27 | {
28 | const T* pEnd1 = pX + length;
29 | while (pX < pEnd1) {
30 | *pX++ += *pY++;
31 | }
32 | }
33 |
34 | static void ComputeSum_SSE(std::int8_t* pX, const std::int8_t* pY, DimensionType length);
35 | static void ComputeSum_AVX(std::int8_t* pX, const std::int8_t* pY, DimensionType length);
36 | static void ComputeSum_AVX512(std::int8_t* pX, const std::int8_t* pY, DimensionType length);
37 |
38 | static void ComputeSum_SSE(std::uint8_t* pX, const std::uint8_t* pY, DimensionType length);
39 | static void ComputeSum_AVX(std::uint8_t* pX, const std::uint8_t* pY, DimensionType length);
40 | static void ComputeSum_AVX512(std::uint8_t* pX, const std::uint8_t* pY, DimensionType length);
41 |
42 | static void ComputeSum_SSE(std::int16_t* pX, const std::int16_t* pY, DimensionType length);
43 | static void ComputeSum_AVX(std::int16_t* pX, const std::int16_t* pY, DimensionType length);
44 | static void ComputeSum_AVX512(std::int16_t* pX, const std::int16_t* pY, DimensionType length);
45 |
46 | static void ComputeSum_SSE(float* pX, const float* pY, DimensionType length);
47 | static void ComputeSum_AVX(float* pX, const float* pY, DimensionType length);
48 | static void ComputeSum_AVX512(float* pX, const float* pY, DimensionType length);
49 |
50 | template
51 | static inline void ComputeSum(T* p1, const T* p2, DimensionType length)
52 | {
53 | auto func = SumCalcSelector();
54 | return func(p1, p2, length);
55 | }
56 | };
57 |
58 | template
59 | inline SumCalcReturn SumCalcSelector()
60 | {
61 | if (InstructionSet::AVX512())
62 | {
63 | return &(SIMDUtils::ComputeSum_AVX512);
64 | }
65 | bool isSize4 = (sizeof(T) == 4);
66 | if (InstructionSet::AVX2() || (isSize4 && InstructionSet::AVX()))
67 | {
68 | return &(SIMDUtils::ComputeSum_AVX);
69 | }
70 | if (InstructionSet::SSE2() || (isSize4 && InstructionSet::SSE()))
71 | {
72 | return &(SIMDUtils::ComputeSum_SSE);
73 | }
74 | return &(SIMDUtils::ComputeSum_Naive);
75 | }
76 | }
77 | }
78 |
79 | #endif // _SPTAG_COMMON_SIMDUTILS_H_
80 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/WorkSpacePool.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_COMMON_WORKSPACEPOOL_H_
5 | #define _SPTAG_COMMON_WORKSPACEPOOL_H_
6 |
7 | #include "WorkSpace.h"
8 | #include "inc/Helper/ConcurrentSet.h"
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | namespace SPTAG
15 | {
16 | namespace COMMON
17 | {
18 |
19 | template
20 | class WorkSpacePool
21 | {
22 | public:
23 | WorkSpacePool() {}
24 |
25 | ~WorkSpacePool()
26 | {
27 | std::shared_ptr workspace;
28 | while (m_workSpacePool.try_pop(workspace))
29 | {
30 | workspace.reset();
31 | }
32 | T::Reset();
33 | }
34 |
35 | std::shared_ptr Rent()
36 | {
37 | std::shared_ptr workSpace;
38 | {
39 | if (m_workSpacePool.try_pop(workSpace))
40 | {
41 | }
42 | else
43 | {
44 | workSpace.reset(new T(m_workSpace));
45 | }
46 | }
47 | return workSpace;
48 | }
49 |
50 | void Return(const std::shared_ptr& p_workSpace)
51 | {
52 | m_workSpacePool.push(p_workSpace);
53 | }
54 |
55 | void Init(int size, ...)
56 | {
57 | va_list args;
58 | va_start(args, size);
59 | m_workSpace.Initialize(args);
60 | va_end(args);
61 | for (int i = 0; i < size; i++)
62 | {
63 | std::shared_ptr workSpace(new T(m_workSpace));
64 | m_workSpacePool.push(std::move(workSpace));
65 | }
66 | }
67 |
68 | private:
69 | Helper::Concurrent::ConcurrentQueue> m_workSpacePool;
70 | T m_workSpace;
71 | };
72 |
73 | }
74 | }
75 |
76 | #endif // _SPTAG_COMMON_WORKSPACEPOOL_H_
77 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/Common/cuda/log.hxx:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 | //#include
27 | #include
28 | #include
29 | #include
30 | using namespace std;
31 |
32 | #include "params.h"
33 |
34 | enum log_level_t {
35 | LOG_NOTHING,
36 | LOG_CRITICAL,
37 | LOG_ERROR,
38 | LOG_WARNING,
39 | LOG_INFO,
40 | LOG_DEBUG
41 | };
42 |
43 |
44 | #define LOG_ALL(f_, ...) printf((f_), ##__VA_ARGS__)
45 | #define DLOG_ALL(f_, ...) {if(threadIdx.x==0 && blockIdx.x==0 && blockIdx.y==0) printf((f_), ##__VA_ARGS__); }
46 |
47 | #if LOG_LEVEL >= 1
48 | #define LOG_CRIT(f_, ...) printf((f_), ##__VA_ARGS__)
49 | #define DLOG_CRIT(f_, ...) {if(threadIdx.x==0 && blockIdx.x==0) printf((f_), ##__VA_ARGS__); }
50 | #else
51 | #define LOG_CRIT(f_, ...) {}
52 | #define DLOG_CRIT(f_, ...) {}
53 | #endif
54 |
55 | #if LOG_LEVEL >= 2
56 | #define LOG_ERR(f_, ...) printf((f_), ##__VA_ARGS__)
57 | #define DLOG_ERR(f_, ...) {if(threadIdx.x==0 && blockIdx.x==0) printf((f_), ##__VA_ARGS__); }
58 | #else
59 | #define LOG_ERR(f_, ...) {}
60 | #define DLOG_ERR(f_, ...) {}
61 | #endif
62 |
63 | #if LOG_LEVEL >= 3
64 | #define LOG_WARN(f_, ...) printf((f_), ##__VA_ARGS__)
65 | #define DLOG_WARN(f_, ...) {if(threadIdx.x==0 && blockIdx.x==0) printf((f_), ##__VA_ARGS__); }
66 | #else
67 | #define LOG_WARN(f_, ...) {}
68 | #define DLOG_WARN(f_, ...) {}
69 | #endif
70 |
71 | #if LOG_LEVEL >= 4
72 | #define LOG_INFO(f_, ...) printf((f_), ##__VA_ARGS__)
73 | #define DLOG_INFO(f_, ...) {if(threadIdx.x==0 && blockIdx.x==0) printf((f_), ##__VA_ARGS__); }
74 | #else
75 | #define LOG_INFO(f_, ...) {}
76 | #define DLOG_INFO(f_, ...) {}
77 | #endif
78 |
79 | #if LOG_LEVEL >= 5
80 | #define LOG_DEBUG(f_, ...) printf((f_), ##__VA_ARGS__)
81 | #define DLOG_DEBUG(f_, ...) {if(threadIdx.x==0 && blockIdx.x==0) printf((f_), ##__VA_ARGS__); }
82 | #else
83 | #define LOG_DEBUG(f_, ...) {}
84 | #define DLOG_DEBUG(f_, ...) {}
85 | #endif
86 |
87 | #define STR_EXPAND(arg) #arg
88 | #define STR(arg) STR_EXPAND(arg)
89 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/MultiIndexScan.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_MULTI_INDEX_SCAN_H
5 | #define _SPTAG_MULTI_INDEX_SCAN_H
6 |
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #include "ResultIterator.h"
17 | #include "VectorIndex.h"
18 | #include
19 | namespace SPTAG
20 | {
21 | class MultiIndexScan
22 | {
23 | public:
24 | MultiIndexScan();
25 | MultiIndexScan(std::vector> vecIndices,
26 | std::vector p_targets,
27 | unsigned int k,
28 | float (*rankFunction)(std::vector),
29 | bool useTimer,
30 | int termCondVal,
31 | int searchLimit
32 | );
33 | ~MultiIndexScan();
34 | void Init(std::vector> vecIndices,
35 | std::vector p_targets,
36 | std::vector weight,
37 | unsigned int k,
38 | bool useTimer,
39 | int termCondVal,
40 | int searchLimit);
41 | bool Next(BasicResult& result);
42 | void Close();
43 |
44 | private:
45 | std::vector> indexIters;
46 | std::vector> fwdLUTs;
47 | std::unordered_set seenSet;
48 | std::vector p_data_array;
49 | std::vector weight;
50 |
51 | unsigned int k;
52 |
53 |
54 |
55 | bool useTimer;
56 | unsigned int termCondVal;
57 | int searchLimit;
58 | std::chrono::time_point t_start;
59 |
60 | float (*func)(std::vector);
61 |
62 | unsigned int consecutive_drops;
63 |
64 | bool terminate;
65 | using pq_item = std::pair;
66 | class pq_item_compare
67 | {
68 | public:
69 | bool operator()(const pq_item& lhs, const pq_item& rhs)
70 | {
71 | return lhs.first < rhs.first;
72 | }
73 | };
74 | std::priority_queue, pq_item_compare> pq;
75 | std::stack outputStk;
76 | float WeightedRankFunc(std::vector);
77 |
78 | };
79 | } // namespace SPTAG
80 | #endif
81 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/ResultIterator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_RESULT_ITERATOR_H
5 | #define _SPTAG_RESULT_ITERATOR_H
6 |
7 | #include
8 |
9 | #include "VectorIndex.h"
10 | #include "SearchQuery.h"
11 |
12 | typedef SPTAG::VectorIndex VectorIndex;
13 | typedef SPTAG::ByteArray ByteArray;
14 | typedef SPTAG::QueryResult QueryResult;
15 |
16 | class ResultIterator
17 | {
18 | public:
19 | ResultIterator(const void* p_index, const void* p_target, bool p_searchDeleted, int p_workspaceBatch);
20 |
21 | ~ResultIterator();
22 |
23 | void* GetWorkSpace();
24 |
25 | virtual std::shared_ptr Next(int batch);
26 |
27 | virtual bool GetRelaxedMono();
28 |
29 | virtual void Close();
30 |
31 | const void* GetTarget();
32 |
33 | protected:
34 | const VectorIndex* m_index;
35 | const void* m_target;
36 | ByteArray m_byte_target;
37 | std::shared_ptr m_queryResult;
38 | void* m_workspace;
39 | bool m_searchDeleted;
40 | bool m_isFirstResult;
41 | int m_batch = 1;
42 | };
43 |
44 | #endif
--------------------------------------------------------------------------------
/AnnService/inc/Core/SPANN/SPANNResultIterator.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_SPANN_RESULT_ITERATOR_H
5 | #define _SPTAG_SPANN_RESULT_ITERATOR_H
6 |
7 | #include
8 |
9 | #include "inc/Core/SPANN/Index.h"
10 | #include "inc/Core/SearchQuery.h"
11 | #include "inc/Core/ResultIterator.h"
12 | #include "inc/Core/Common/WorkSpace.h"
13 | #include "inc/Core/SPANN/IExtraSearcher.h"
14 |
15 | namespace SPTAG
16 | {
17 | namespace SPANN
18 | {
19 | template
20 | class SPANNResultIterator : public ResultIterator
21 | {
22 | public:
23 | SPANNResultIterator(const Index* p_spannIndex, const VectorIndex* p_index, const void* p_target,
24 | std::unique_ptr p_extraWorkspace,
25 | int p_batch): ResultIterator(p_index, p_target, false, p_batch),
26 | m_spannIndex(p_spannIndex),
27 | m_extraWorkspace(std::move(p_extraWorkspace))
28 | {
29 | m_headQueryResult = std::make_unique(p_target, p_batch, false);
30 | }
31 |
32 | ~SPANNResultIterator()
33 | {
34 | Close();
35 | }
36 |
37 | virtual std::shared_ptr Next(int batch)
38 | {
39 | if (m_queryResult == nullptr) {
40 | m_queryResult = std::make_unique(m_target, batch, true);
41 | }
42 | else if (batch <= m_queryResult->GetResultNum()) {
43 | m_queryResult->SetResultNum(batch);
44 | }
45 | else {
46 | batch = m_queryResult->GetResultNum();
47 | }
48 |
49 | m_queryResult->Reset();
50 | if (m_workspace == nullptr) return m_queryResult;
51 |
52 | int resultCount = 0;
53 | m_spannIndex->SearchIndexIterative(*m_headQueryResult, *m_queryResult,
54 | (COMMON::WorkSpace*)GetWorkSpace(), m_extraWorkspace.get(), batch, resultCount, m_isFirstResult);
55 | m_isFirstResult = false;
56 |
57 | for (int i = 0; i < resultCount; i++)
58 | {
59 | m_queryResult->GetResult(i)->RelaxedMono = m_extraWorkspace->m_relaxedMono;
60 | }
61 | m_queryResult->SetResultNum(resultCount);
62 | return m_queryResult;
63 | }
64 |
65 | virtual bool GetRelaxedMono()
66 | {
67 | if (m_extraWorkspace == nullptr) return false;
68 |
69 | return m_extraWorkspace->m_relaxedMono;
70 | }
71 |
72 | virtual void Close()
73 | {
74 | ResultIterator::Close();
75 | if (m_extraWorkspace != nullptr) {
76 | m_spannIndex->SearchIndexIterativeEnd(std::move(m_extraWorkspace));
77 | m_extraWorkspace = nullptr;
78 | }
79 | }
80 |
81 | private:
82 | const Index* m_spannIndex;
83 | std::unique_ptr m_headQueryResult;
84 | std::unique_ptr m_extraWorkspace;
85 | };
86 | }// namespace SPANN
87 | } // namespace SPTAG
88 | #endif
89 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/SearchResult.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_SEARCHRESULT_H_
5 | #define _SPTAG_SEARCHRESULT_H_
6 |
7 | #include "CommonDataStructure.h"
8 |
9 | namespace SPTAG
10 | {
11 | struct NodeDistPair
12 | {
13 | SizeType node;
14 | float distance;
15 |
16 | NodeDistPair(SizeType _node = -1, float _distance = MaxDist) : node(_node), distance(_distance) {}
17 |
18 | inline bool operator < (const NodeDistPair& rhs) const
19 | {
20 | return distance < rhs.distance;
21 | }
22 |
23 | inline bool operator > (const NodeDistPair& rhs) const
24 | {
25 | return distance > rhs.distance;
26 | }
27 | };
28 |
29 | struct Edge
30 | {
31 | SizeType node;
32 | float distance;
33 | SizeType tonode;
34 | Edge() : node(MaxSize), distance(MaxDist), tonode(MaxSize) {}
35 | };
36 |
37 | struct EdgeCompare
38 | {
39 | inline bool operator()(const Edge& a, int b) const
40 | {
41 | return a.node < b;
42 | };
43 |
44 | inline bool operator()(int a, const Edge& b) const
45 | {
46 | return a < b.node;
47 | };
48 |
49 | inline bool operator()(const Edge& a, const Edge& b) const
50 | {
51 | if (a.node == b.node)
52 | {
53 | if (a.distance == b.distance)
54 | {
55 | return a.tonode < b.tonode;
56 | }
57 |
58 | return a.distance < b.distance;
59 | }
60 |
61 | return a.node < b.node;
62 | };
63 | };
64 |
65 | struct BasicResult
66 | {
67 | SizeType VID;
68 | float Dist;
69 | ByteArray Meta;
70 | bool RelaxedMono;
71 |
72 | BasicResult() : VID(-1), Dist(MaxDist), RelaxedMono(false) {}
73 |
74 | BasicResult(SizeType p_vid, float p_dist) : VID(p_vid), Dist(p_dist), RelaxedMono(false) {}
75 |
76 | BasicResult(SizeType p_vid, float p_dist, ByteArray p_meta) : VID(p_vid), Dist(p_dist), Meta(p_meta), RelaxedMono(false) {}
77 | BasicResult(SizeType p_vid, float p_dist, ByteArray p_meta, bool p_relaxedMono) : VID(p_vid), Dist(p_dist), Meta(p_meta), RelaxedMono(p_relaxedMono) {}
78 | };
79 |
80 | } // namespace SPTAG
81 |
82 | #endif // _SPTAG_SEARCHRESULT_H_
83 |
--------------------------------------------------------------------------------
/AnnService/inc/Core/VectorSet.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_VECTORSET_H_
5 | #define _SPTAG_VECTORSET_H_
6 |
7 | #include "CommonDataStructure.h"
8 |
9 | namespace SPTAG
10 | {
11 |
12 | class VectorSet
13 | {
14 | public:
15 | VectorSet();
16 |
17 | virtual ~VectorSet();
18 |
19 | virtual VectorValueType GetValueType() const = 0;
20 |
21 | virtual void* GetVector(SizeType p_vectorID) const = 0;
22 |
23 | virtual void* GetData() const = 0;
24 |
25 | virtual DimensionType Dimension() const = 0;
26 |
27 | virtual SizeType Count() const = 0;
28 |
29 | virtual bool Available() const = 0;
30 |
31 | virtual ErrorCode Save(const std::string& p_vectorFile) const = 0;
32 |
33 | virtual ErrorCode AppendSave(const std::string& p_vectorFile) const = 0;
34 |
35 | virtual SizeType PerVectorDataSize() const = 0;
36 |
37 | virtual void Normalize(int p_threads) = 0;
38 | };
39 |
40 |
41 | class BasicVectorSet : public VectorSet
42 | {
43 | public:
44 | BasicVectorSet(const ByteArray& p_bytesArray,
45 | VectorValueType p_valueType,
46 | DimensionType p_dimension,
47 | SizeType p_vectorCount);
48 |
49 | virtual ~BasicVectorSet();
50 |
51 | virtual VectorValueType GetValueType() const;
52 |
53 | virtual void* GetVector(SizeType p_vectorID) const;
54 |
55 | virtual void* GetData() const;
56 |
57 | virtual DimensionType Dimension() const;
58 |
59 | virtual SizeType Count() const;
60 |
61 | virtual bool Available() const;
62 |
63 | virtual ErrorCode Save(const std::string& p_vectorFile) const;
64 |
65 | virtual ErrorCode AppendSave(const std::string& p_vectorFile) const;
66 |
67 | virtual SizeType PerVectorDataSize() const;
68 |
69 | virtual void Normalize(int p_threads);
70 |
71 | private:
72 | ByteArray m_data;
73 |
74 | VectorValueType m_valueType;
75 |
76 | DimensionType m_dimension;
77 |
78 | SizeType m_vectorCount;
79 |
80 | size_t m_perVectorDataSize;
81 | };
82 |
83 | } // namespace SPTAG
84 |
85 | #endif // _SPTAG_VECTORSET_H_
86 |
--------------------------------------------------------------------------------
/AnnService/inc/Helper/Base64Encode.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_HELPER_BASE64ENCODE_H_
5 | #define _SPTAG_HELPER_BASE64ENCODE_H_
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | namespace SPTAG
12 | {
13 | namespace Helper
14 | {
15 | namespace Base64
16 | {
17 |
18 | bool Encode(const std::uint8_t* p_in, std::size_t p_inLen, char* p_out, std::size_t& p_outLen);
19 |
20 | bool Encode(const std::uint8_t* p_in, std::size_t p_inLen, std::ostream& p_out, std::size_t& p_outLen);
21 |
22 | bool Decode(const char* p_in, std::size_t p_inLen, std::uint8_t* p_out, std::size_t& p_outLen);
23 |
24 | std::size_t CapacityForEncode(std::size_t p_inLen);
25 |
26 | std::size_t CapacityForDecode(std::size_t p_inLen);
27 |
28 |
29 | } // namespace Base64
30 | } // namespace Helper
31 | } // namespace SPTAG
32 |
33 | #endif // _SPTAG_HELPER_BASE64ENCODE_H_
34 |
--------------------------------------------------------------------------------
/AnnService/inc/Helper/CommonHelper.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_HELPER_COMMONHELPER_H_
5 | #define _SPTAG_HELPER_COMMONHELPER_H_
6 |
7 | #include "inc/Core/Common.h"
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 |
17 | namespace SPTAG
18 | {
19 | namespace Helper
20 | {
21 | namespace StrUtils
22 | {
23 |
24 | void ToLowerInPlace(std::string& p_str);
25 |
26 | std::vector SplitString(const std::string& p_str, const std::string& p_separator);
27 |
28 | std::pair FindTrimmedSegment(const char* p_begin,
29 | const char* p_end,
30 | const std::function& p_isSkippedChar);
31 |
32 | bool StartsWith(const char* p_str, const char* p_prefix);
33 |
34 | bool StrEqualIgnoreCase(const char* p_left, const char* p_right);
35 |
36 | std::string ReplaceAll(const std::string& orig, const std::string& from, const std::string& to);
37 |
38 | } // namespace StrUtils
39 | } // namespace Helper
40 | } // namespace SPTAG
41 |
42 | #endif // _SPTAG_HELPER_COMMONHELPER_H_
43 |
--------------------------------------------------------------------------------
/AnnService/inc/Helper/Concurrent.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_HELPER_CONCURRENT_H_
5 | #define _SPTAG_HELPER_CONCURRENT_H_
6 |
7 |
8 | #include
9 | #include
10 | #include
11 |
12 |
13 | namespace SPTAG
14 | {
15 | namespace Helper
16 | {
17 | namespace Concurrent
18 | {
19 |
20 | class SpinLock
21 | {
22 | public:
23 | SpinLock() = default;
24 |
25 | void Lock() noexcept
26 | {
27 | while (m_lock.test_and_set(std::memory_order_acquire))
28 | {
29 | }
30 | }
31 |
32 | void Unlock() noexcept
33 | {
34 | m_lock.clear(std::memory_order_release);
35 | }
36 |
37 | SpinLock(const SpinLock&) = delete;
38 | SpinLock& operator = (const SpinLock&) = delete;
39 |
40 | private:
41 | std::atomic_flag m_lock = ATOMIC_FLAG_INIT;
42 | };
43 |
44 | template
45 | class LockGuard {
46 | public:
47 | LockGuard(Lock& lock) noexcept
48 | : m_lock(lock) {
49 | lock.Lock();
50 | }
51 |
52 | LockGuard(Lock& lock, std::adopt_lock_t) noexcept
53 | : m_lock(lock) {}
54 |
55 | ~LockGuard() {
56 | m_lock.Unlock();
57 | }
58 |
59 | LockGuard(const LockGuard&) = delete;
60 | LockGuard& operator=(const LockGuard&) = delete;
61 |
62 | private:
63 | Lock& m_lock;
64 | };
65 |
66 |
67 | class WaitSignal
68 | {
69 | public:
70 | WaitSignal();
71 |
72 | WaitSignal(std::uint32_t p_unfinished);
73 |
74 | ~WaitSignal();
75 |
76 | void Reset(std::uint32_t p_unfinished);
77 |
78 | void Wait();
79 |
80 | void FinishOne();
81 |
82 | private:
83 | std::atomic m_unfinished;
84 |
85 | std::atomic_bool m_isWaiting;
86 |
87 | std::mutex m_mutex;
88 |
89 | std::condition_variable m_cv;
90 | };
91 |
92 |
93 | } // namespace Base64
94 | } // namespace Helper
95 | } // namespace SPTAG
96 |
97 | #endif // _SPTAG_HELPER_CONCURRENT_H_
98 |
--------------------------------------------------------------------------------
/AnnService/inc/Helper/DynamicNeighbors.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace SPTAG {
6 | namespace Helper {
7 | class DynamicNeighbors
8 | {
9 | public:
10 | DynamicNeighbors(const int* p_data, const int p_length);
11 |
12 | ~DynamicNeighbors();
13 |
14 | int operator[](const int p_id) const;
15 |
16 | int Size() const;
17 |
18 | private:
19 | const int* const c_data;
20 |
21 | const int c_length;
22 | };
23 |
24 |
25 | class DynamicNeighborsSet
26 | {
27 | public:
28 | DynamicNeighborsSet(const char* p_filePath);
29 |
30 | ~DynamicNeighborsSet();
31 |
32 | DynamicNeighbors operator[](const int p_id) const;
33 |
34 | int VectorCount() const
35 | {
36 | return m_vectorCount;
37 | }
38 |
39 | private:
40 | std::unique_ptr m_data;
41 |
42 | std::unique_ptr m_neighborOffset;
43 |
44 | int m_vectorCount;
45 | };
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/AnnService/inc/Helper/SimpleIniReader.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT License.
3 |
4 | #ifndef _SPTAG_HELPER_INIREADER_H_
5 | #define _SPTAG_HELPER_INIREADER_H_
6 |
7 | #include "inc/Core/Common.h"
8 | #include "StringConvert.h"
9 |
10 | #include
11 | #include