diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..facde9f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.apm/ diff --git a/Bin/Cpu/libfaiss.so b/Bin/Cpu/libfaiss.so new file mode 100755 index 0000000..5a7ac32 Binary files /dev/null and b/Bin/Cpu/libfaiss.so differ diff --git a/Bin/Cpu/libfaiss_c.so b/Bin/Cpu/libfaiss_c.so new file mode 100755 index 0000000..c3c9aa0 Binary files /dev/null and b/Bin/Cpu/libfaiss_c.so differ diff --git a/Bin/Gpu/libfaiss.so b/Bin/Gpu/libfaiss.so new file mode 100755 index 0000000..ab51404 Binary files /dev/null and b/Bin/Gpu/libfaiss.so differ diff --git a/Bin/Gpu/libfaiss_c.so b/Bin/Gpu/libfaiss_c.so new file mode 100755 index 0000000..e686137 Binary files /dev/null and b/Bin/Gpu/libfaiss_c.so differ diff --git a/BufferList.alusus b/BufferList.alusus new file mode 100644 index 0000000..24fffba --- /dev/null +++ b/BufferList.alusus @@ -0,0 +1,37 @@ +@merge module Faiss { + class BufferList { + @expname[faiss_BufferList_new] + func new( + obj: ref[ref[BufferList]], + bufferSize: ArchWord + ): Int; + + @expname[faiss_BufferList_free] + func free( + bl: ref[BufferList] + ); + + @expname[faiss_BufferList_append_buffer] + handler this.appendBuffer(): Int; + + @expname[faiss_BufferList_add] + handler this.add( + id: Int[64], + dis: Float + ): Int; + + @expname[faiss_BufferList_copy_range] + handler this.copyRange( + ofs: ArchWord, + n: ArchWord, + destIds: ref[array[Int[64]]], + destDis: ref[array[Float]] + ): Int; + + @expname[faiss_BufferList_buffer_size] + handler this.bufferSize: ArchWord; + + @expname[faiss_BufferList_wp] + handler this.wp: ArchWord; + } +} diff --git a/Clustering.alusus b/Clustering.alusus new file mode 100644 index 0000000..3ef5422 --- /dev/null +++ b/Clustering.alusus @@ -0,0 +1,121 @@ +@merge module Faiss { + class Clustering { + @expname[faiss_Clustering_new] + func new( + out: ref[ref[Clustering]], + d: Int, + k: Int + ): Int; + + @expname[faiss_Clustering_new_with_params] + func new( + out: ref[ref[Clustering]], + d: Int, + k: Int, + params: ptr[ClusteringParameters] + ): Int; + + @expname[faiss_Clustering_free] + func free( + clustering: ref[Clustering] + ); + + @expname[faiss_Clustering_niter] + handler this.nIter: Int; + + @expname[faiss_Clustering_nredo] + handler this.nRedo: Int; + + @expname[faiss_Clustering_verbose] + handler this.verbose: Int; + + @expname[faiss_Clustering_spherical] + handler this.spherical: Int; + + @expname[faiss_Clustering_int_centroids] + handler this.intCentroids: Int; + + @expname[faiss_Clustering_update_index] + handler this.updateIndex: Int; + + @expname[faiss_Clustering_frozen_centroids] + handler this.frozenCentroids: Int; + + @expname[faiss_Clustering_min_points_per_centroid] + handler this.minPointsPerCentroid: Int; + + @expname[faiss_Clustering_max_points_per_centroid] + handler this.maxPointsPerCentroid: Int; + + @expname[faiss_Clustering_seed] + handler this.seed: Int; + + @expname[faiss_Clustering_decode_block_size] + handler this.decodeBlockSize: ArchWord; + + @expname[faiss_Clustering_d] + handler this.d: ArchWord; + + @expname[faiss_Clustering_k] + handler this.k: ArchWord; + + @expname[faiss_Clustering_centroids] + handler this.getCentroids( + centroids: ref[ref[array[Float]]], + size: ref[ArchWord] + ); + + @expname[faiss_Clustering_iteration_stats] + handler this.getIterationStats( + stats_out: ref[ref[ClusteringIterationStats]], + size: ref[ArchWord] + ); + + @expname[faiss_Clustering_train] + handler this.train( + n: Int[64], + x: ref[Float], + index: ref[Index] + ): Int; + } + + class ClusteringParameters { + def niter: Int; ///< clustering iterations + def nredo: Int; ///< redo clustering this many times and keep best + + def verbose: Int; ///< (bool) + def spherical: Int; ///< (bool) do we want normalized centroids? + def intCentroids: Int; ///< (bool) round centroids coordinates to integer + def updateIndex: Int; ///< (bool) update index after each iteration? + def frozenCentroids: Int; ///< (bool) use the centroids provided as input and do + ///< not change them during iterations + + def minPointsPerCentroid: Int; ///< otherwise you get a warning + def maxPointsPerCentroid: Int; ///< to limit size of dataset + + def seed: Int; ///< seed for the random number generator + def decodeBlockSize: ArchWord; ///< how many vectors at a time to decode + + @expname[faiss_ClusteringParameters_init] + func init( + params: ref[ref[ClusteringParameters]] + ); + } + + class ClusteringIterationStats { + @expname[faiss_ClusteringIterationStats_obj] + handler this.obj: Float; + + @expname[faiss_ClusteringIterationStats_time] + handler this.time: Float[64]; + + @expname[faiss_ClusteringIterationStats_time_search] + handler this.timeSearch: Float[64]; + + @expname[faiss_ClusteringIterationStats_imbalance_factor] + handler this.imbalanceFactor: Float[64]; + + @expname[faiss_ClusteringIterationStats_nsplit] + handler this.nSplit: Int; + } +} diff --git a/DistanceComputer.alusus b/DistanceComputer.alusus new file mode 100644 index 0000000..2b0d608 --- /dev/null +++ b/DistanceComputer.alusus @@ -0,0 +1,24 @@ +@merge module Faiss { + class DistanceComputer { + @expname[faiss_DistanceComputer_set_query] + handler this.setQuery( + x: ref[array[Float]] + ): Int; + + @expname[faiss_DistanceComputer_vector_to_query_dis] + handler this.vectorToQueryDis( + i: Int[64], + qd: ref[array[Float]] + ): Int; + + @expname[faiss_DistanceComputer_symmetric_dis] + handler this.symmetricDis( + i: Int[64], + j: Int[64], + vd: ref[array[Float]] + ): Int; + + @expname[faiss_DistanceComputer_free] + func free(dc: ref[DistanceComputer]); + } +} diff --git a/Examples/example.alusus b/Examples/example.alusus new file mode 100644 index 0000000..51c0182 --- /dev/null +++ b/Examples/example.alusus @@ -0,0 +1,52 @@ +import "Srl/Console"; +import "Srl/Array"; +import "Apm"; +Apm.importFile("Alusus/Faiss"); +use Srl; +use Faiss; + +// Input data +def D: Int = 4; +def xb: Array[Float]({ + 1.0, 2.0, 3.0, 4.0, + 2.0, 3.0, 4.0, 5.0, + 10.0, 11.0, 12.0, 13.0, + 11.0, 12.0, 13.0, 14.0, + 5.0, 6.0, 7.0, 8.0 +}); +def xq: Array[Float]({ + 1.5, 2.5, 3.5, 4.5, + 10.5, 11.5, 12.5, 13.5 +}); + +// Prepare the index +def index: ref[Index]; +if Index.new(index, D, "Flat", MetricType.INNER_PRODUCT) == 0 { + Console.print("Index.new: OK \n"); +} else { + Console.print("Index.new: ERROR \n"); +} +index.add(xb.getLength() / D, xb.buf); + +// Perform the search +def labels: array[Int[64], 6]; +def distances: array[Float, 6]; +index.search(xq.getLength() / D, xq.buf, 3, distances, labels); + +// Print the resutls +def i: Int; +def j: Int; +for i = 0, i < xq.getLength() / D, i++ { + Console.print("Query %i:\n", i); + for j = 0, j < 3, j++ { + Console.print(" Neighbor "); + Console.print(j); + Console.print(", idx= "); + Console.print(labels(i * 3 + j)); + Console.print(", dist= "); + Console.print(distances(i * 3 + j)); + Console.print("\n"); + } +} + +Index.free(index); diff --git a/Examples/example2.alusus b/Examples/example2.alusus new file mode 100644 index 0000000..1e8ea6c --- /dev/null +++ b/Examples/example2.alusus @@ -0,0 +1,59 @@ +import "Srl/Console"; +import "Srl/Array"; +import "Apm"; +Apm.importFile("Alusus/Faiss"); +use Faiss; +use Srl; + +def D: int = 8; +def NB: Int[64] = 80; +def NQ: Int[64] = 2; +def K: Int[64] = 3; + +// Prepare the data +def xb: Array[Float]; +def i: Int[64] = 0; +for i = 0, i < NB * D, i++ { + xb.add((i % D) + 1); +} +def xq: Array[Float]; +for i = 0, i < NQ * D, i++ { + xq.add((i % D) + 1.5); +} + +// Prepare the index +def index: ref[IndexIvf]; +if Index.new(index, D, "IVF1,Flat", MetricType.L2) == 0 { + Console.print("Index.new: OK\n"); +} else { + Console.print("Index.new: ERROR\n"); +} +index.train(NB, xb.buf); +index.add(NB, xb.buf); + +def ps: ref[ParameterSpace]; +ParameterSpace.new(ps); +ps.setIndexParameter(index, "nprobe", 2.0); +ParameterSpace.free(ps); + +// Perform the search +def labels: array[Int[64], 6]; +def distances: array[float, 6]; +index.search(NQ, xq.buf, 3, distances, labels); + +// Print the results +def j: int = 0; +for i = 0, i < NQ, i++ { + Console.print("Query %i:\n", i); + for j = 0, j < 3, j++ { + Console.print(" Neighbor "); + Console.print(j); + Console.print(", idx= "); + Console.print(labels(i * 3 + j)); + Console.print(", dist= "); + Console.print(distances(i * 3 + j)); + Console.print("\n"); + } +} + +Index.free(index); diff --git "a/Examples/\331\205\330\253\330\247\331\204.\330\243\330\263\330\263" "b/Examples/\331\205\330\253\330\247\331\204.\330\243\330\263\330\263" new file mode 100644 index 0000000..a3abe1a --- /dev/null +++ "b/Examples/\331\205\330\253\330\247\331\204.\330\243\330\263\330\263" @@ -0,0 +1,52 @@ +اشمل "مـتم/طـرفية"؛ +اشمل "مـتم/مـصفوفة"؛ +اشمل "مـحا"؛ +مـحا.اشمل_ملف("Alusus/Faiss"، "فـيس.أسس")؛ +استخدم مـتم؛ +استخدم فـيس؛ + +// بيانات الإدخال +عرف _ب_: صحيح = 4؛ +عرف سب: مـصفوفة[عـائم]({ + 1.0، 2.0، 3.0، 4.0، + 2.0، 3.0، 4.0، 5.0، + 10.0، 11.0، 12.0، 13.0، + 11.0، 12.0، 13.0، 14.0، + 5.0، 6.0، 7.0، 8.0 +})؛ +عرف سس: مـصفوفة[عـائم]({ + 1.5، 2.5، 3.5، 4.5، + 10.5، 11.5، 12.5، 13.5 +})؛ + +// تحضير الفهرس +عرف الفهرس: سند[فـهرس]؛ +إذا فـهرس.أنشئ(الفهرس، _ب_، "Flat"، نـوع_قياس._نتاج_داخلي_) == 0 { + طـرفية.اطبع("فـهرس.أنشئ: نجح\ج")؛ +} وإلا { + طـرفية.اطبع("فـهرس.أنشئ: خطأ\ج")؛ +} +الفهرس.أضف(سب.هات_الطول() / _ب_، سب.صوان)؛ + +// تنفيذ البحث +عرف الوسوم: مصفوفة[صحيح[64]، 6]؛ +عرف المسافات: مصفوفة[عـائم، 6]؛ +الفهرس.ابحث(سس.هات_الطول() / _ب_، سس.صوان، 3، المسافات، الوسوم)؛ + +// طباعة النتائج +عرف ت: صحيح؛ +عرف ج: صحيح؛ +لكل ت = 0، ت < سس.هات_الطول() / _ب_، ت++ { + طـرفية.اطبع("الاستعلام %i:\n"، ت)؛ + لكل ج = 0، ج < 3، ج++ { + طـرفية.اطبع(" الجار ")؛ + طـرفية.اطبع(ج)؛ + طـرفية.اطبع("، رقم= ")؛ + طـرفية.اطبع(الوسوم(ت * 3 + ج))؛ + طـرفية.اطبع("، مسافة= ")؛ + طـرفية.اطبع(المسافات(ت * 3 + ج))؛ + طـرفية.اطبع("\n")؛ + } +} + +فـهرس.حرر(الفهرس)؛ diff --git "a/Examples/\331\205\330\253\330\247\331\2042.\330\243\330\263\330\263" "b/Examples/\331\205\330\253\330\247\331\2042.\330\243\330\263\330\263" new file mode 100644 index 0000000..7851cce --- /dev/null +++ "b/Examples/\331\205\330\253\330\247\331\2042.\330\243\330\263\330\263" @@ -0,0 +1,59 @@ +اشمل "مـتم/طـرفية"؛ +اشمل "مـتم/مـصفوفة"؛ +اشمل "مـحا"؛ +مـحا.اشمل_ملف("Alusus/Faiss"، "فـيس.أسس")؛ +استخدم مـتم؛ +استخدم فـيس؛ + +عرف بـ: صحيح = 8؛ +عرف عب: صحيح[64] = 80؛ +عرف عس: صحيح[64] = 2؛ +عرف ك: صحيح[64] = 3؛ + +// تحضير البيانات +عرف سب: مـصفوفة[عـائم]؛ +عرف ت: صحيح[64] = 0؛ +لكل ت = 0، ت < عب * بـ، ت++ { + سب.أضف((ت % بـ) + 1)؛ +} +عرف سس: مـصفوفة[عـائم]؛ +لكل ت = 0، ت < عس * بـ، ت++ { + سس.أضف((ت % بـ) + 1.5)؛ +} + +// تحضير الفهرس +عرف الفهرس: سند[فـهرس_ملف_معكوس]؛ +إذا فـهرس.أنشئ(الفهرس، بـ، "IVF1,Flat"، نـوع_قياس._ل2_) == 0 { + طـرفية.اطبع("فـهرس.أنشئ: نجح\n")؛ +} وإلا { + طـرفية.اطبع("فـهرس.أنشئ: خطأ\n")؛ +} +الفهرس.درب(عب، سب.صوان)؛ +الفهرس.أضف(عب، سب.صوان)؛ + +عرف فض: سند[فـضاء_وسيط]؛ +فـضاء_وسيط.أنشئ(فض)؛ +فض.حدد_وسيط_فهرس(الفهرس، "nprobe"، 2.0)؛ +فـضاء_وسيط.حرر(فض)؛ + +// تنفيذ البحث +عرف الوسوم: مصفوفة[صحيح[64]، 6]؛ +عرف المسافات: مصفوفة[عـائم، 6]؛ +الفهرس.ابحث(عس، سس.صوان، 3، المسافات، الوسوم)؛ + +// طباعة النتائج +عرف ج: صحيح = 0؛ +لكل ت = 0، ت < عس، ت++ { + طـرفية.اطبع("الاستعلام %i:\n"، ت)؛ + لكل ج = 0، ج < 3، ج++ { + طـرفية.اطبع(" الجار ")؛ + طـرفية.اطبع(ج)؛ + طـرفية.اطبع("، رقم= ")؛ + طـرفية.اطبع(الوسوم(ت * 3 + ج))؛ + طـرفية.اطبع("، مسافة= ")؛ + طـرفية.اطبع(المسافات(ت * 3 + ج))؛ + طـرفية.اطبع("\n")؛ + } +} + +فـهرس.حرر(الفهرس)؛ diff --git a/Faiss.alusus b/Faiss.alusus new file mode 100644 index 0000000..c5b68fb --- /dev/null +++ b/Faiss.alusus @@ -0,0 +1,61 @@ +import "Srl/System"; +import "Srl/String"; +import "Core"; + +def useGpu: CharsPtr = Srl.System.getEnv("FAISS_USE_GPU"); +if useGpu == 0 or !Srl.String.isEqual(useGpu, "1") { + Core.importFile("Bin/Cpu/libfaiss.so"); + Core.importFile("Bin/Cpu/libfaiss_c.so"); +} else { + Core.importFile("Bin/Gpu/libfaiss.so"); + Core.importFile("Bin/Gpu/libfaiss_c.so"); +} + +import "ParameterRange"; +import "ParameterSpace"; +import "RangeSearchResult"; +import "RangeSearchPartialResult"; +import "RangeQueryResult"; +import "IdSelector"; +import "BufferList"; +import "DistanceComputer"; +import "Clustering"; +import "Index"; +import "SearchParameters"; + +@merge module Faiss { + def ErrorCode: { + def OK: 0; + def UNKNOWN_EXCEPT: -1; + def FAISS_EXCEPT: -2; + def STD_EXCEPT: -4; + }; + + def MetricType: { + def INNER_PRODUCT: 0; + def L2: 1; + def L1: 2; + def LINF: 3; + def LP: 4; + + def CANBERRA: 20; + def BRAY_CURTIS: 21; + def JENSEN_SHANNON: 22; + } + + @expname[faiss_get_last_error] + func getLastError(): CharsPtr; + + @expname[faiss_kmeans_clustering] + func kmeansClustering( + d: ArchWord, + n: ArchWord, + k: ArchWord, + x: ref[array[Float]], + centroids: ref[array[Float]], + q_error: ref[Float] + ) Int; + + @expname[faiss_get_indexIVF_stats] + func faissGetIndexIvfStats(): ptr[IndexIvfStats]; +} diff --git a/IdSelector.alusus b/IdSelector.alusus new file mode 100644 index 0000000..a6a05dc --- /dev/null +++ b/IdSelector.alusus @@ -0,0 +1,118 @@ +@merge module Faiss { + class IdSelector { + @expname[faiss_IDSelector_free] + func free(sel: ref[IdSelector]); + + @expname[faiss_IDSelector_is_member] + handler this.isMember(id: Int[64]): Int; + } + + class IdSelectorBatch { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorBatch_new] + func new( + p_sel: ref[ref[IdSelectorBatch]], + n: ArchWord, + indices: ref[array[Int[64]]] + ): Int; + + @expname[faiss_IDSelectorBatch_free] + func free( + sel: ref[IdSelectorBatch] + ); + + @expname[faiss_IDSelectorBatch_nbits] + handler this.nbits: Int; + + @expname[faiss_IDSelectorBatch_mask] + handler this.mask: Int[64]; + } + + class IdSelectorBitmap { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorBitmap_new] + func new( + p_sel: ref[ref[IdSelectorBitmap]], + n: ArchWord, + bitmap: ref[array[Word[8]]] + ): Int; + + @expname[faiss_IDSelectorBitmap_free] + func free( + sel: ref[IdSelectorBitmap] + ); + + @expname[faiss_IDSelectorBitmap_n] + handler this.n: ArchWord; + + @expname[faiss_IDSelectorBitmap_bitmap] + handler this.bitmap: ref[array[Word[8]]]; + } + + class IdSelectorRange { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorRange_new] + func new( + p_sel: ref[ref[IdSelectorRange]], + imin: Int[64], + imax: Int[64] + ): Int; + + @expname[faiss_IDSelectorRange_free] + func free( + sel: ref[IdSelectorRange] + ); + + @expname[faiss_IDSelectorRange_imin] + handler this.imin: Int[64]; + + @expname[faiss_IDSelectorRange_imax] + handler this.imax: Int[64]; + } + + class IdSelectorNot { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorNot_new] + func new( + p_sel: ref[ref[IdSelectorNot]], + sel: ref[IdSelector] + ): Int; + } + + class IdSelectorAnd { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorAnd_new] + func new( + p_sel: ref[ref[IdSelectorAnd]], + lhs: ref[IdSelector], + rhs: ref[IdSelector] + ): Int; + } + + class IdSelectorOr { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorOr_new] + func new( + p_sel: ref[ref[IdSelectorOr]], + lhs: ref[IdSelector], + rhs: ref[IdSelector] + ): Int; + } + + class IdSelectorXor { + @injection def idSelector: IdSelector; + + @expname[faiss_IDSelectorXOr_new] + func new( + p_sel: ref[ref[IdSelectorXor]], + lhs: ref[IdSelector], + rhs: ref[IdSelector] + ): Int; + } +} diff --git a/Index.alusus b/Index.alusus new file mode 100644 index 0000000..e0fa2e2 --- /dev/null +++ b/Index.alusus @@ -0,0 +1,562 @@ +@merge module Faiss { + class Index { + @expname[faiss_index_factory] + func new( + obj: ref[ref[Index]], + d: Int, + description: CharsPtr, + metric: Int + ): Int; + + @expname[faiss_clone_index] + func clone( + idx: ref[Index], + out: ref[ref[Index]] + ): Int; + + @expname[faiss_Index_free] + func free(obj: ref[Index]); + + @expname[faiss_Index_d] + handler this.d: Int[64]; + + @expname[faiss_Index_set_d] + handler this.d = Int[64]; + + @expname[faiss_Index_ntotal] + handler this.nTotal: Int[64]; + + @expname[faiss_Index_set_ntotal] + handler this.nTotal = Int[64]; + + @expname[faiss_Index_is_trained] + handler this.isTrained: Int; + + @expname[faiss_Index_metric_type] + handler this.metricType: MetricType; + + @expname[faiss_Index_verbose] + handler this.verbose: Int; + + @expname[faiss_Index_set_verbose] + handler this.verbose = Int; + + @expname[faiss_Index_train] + handler this.train(n: Int[64], x: ref[array[Float]]): Int; + + @expname[faiss_Index_add] + handler this.add(n: Int[64], x: ref[array[Float]]): Int; + + @expname[faiss_Index_add_with_ids] + handler this.add(n: Int[64], x: ref[array[Float]], xids: ref[array[Int[64]]]): Int; + + @expname[faiss_Index_search] + handler this.search( + n: Int[64], + x: ref[array[Float]], + k: Int[64], + distances: ref[array[Float]], + labels: ref[array[Int[64]]] + ): Int; + + @expname[faiss_Index_search_with_params] + handler this.search( + n: Int[64], + x: ref[array[Float]], + k: Int[64], + params: ref[SearchParameters], + distances: ref[array[Float]], + labels: ref[array[Int[64]]] + ): Int; + + @expname[faiss_Index_range_search] + handler this.rangeSearch( + n: Int[64], + x: ref[array[Float]], + radius: Float, + result: ref[RangeSearchResult] + ): Int; + + @expname[faiss_Index_assign] + handler this.assign( + n: Int[64], + x: ref[array[Float]], + labels: ref[array[Int[64]]], + k: Int[64] + ): Int; + + @expname[faiss_Index_reset] + handler this.reset(): Int; + + @expname[faiss_Index_remove_ids] + handler this.removeIds( + sel: ref[IdSelector], + nRemoved: ref[ArchWord] + ): Int; + + @expname[faiss_Index_reconstruct] + handler this.reconstruct( + key: Int[64], + recons: ref[array[Float]] + ): Int; + + @expname[faiss_Index_reconstruct_n] + handler this.reconstruct( + i0: Int[64], + ni: Int[64], + recons: ref[array[Float]] + ): Int; + + @expname[faiss_Index_compute_residual] + handler this.computeResidual( + x: ref[array[Float]], + residual: ref[array[Float]], + key: Int[64] + ): Int; + + @expname[faiss_Index_compute_residual_n] + handler this.computeResidual( + n: Int[64], + x: ref[array[Float]], + residuals: ref[array[Float]], + keys: ref[array[Int[64]]] + ): Int; + + @expname[faiss_Index_sa_code_size] + handler this.getSaCodeSize(size: ref[ArchWord]): Int; + + @expname[faiss_Index_sa_encode] + handler this.saEncode( + n: Int[64], + x: ref[array[Float]], + bytes: ref[array[Word[8]]] + ): Int; + + @expname[faiss_Index_sa_decode] + handler this.saDecode( + n: Int[64], + bytes: ref[array[Word[8]]], + x: ref[array[Float]] + ): Int; + } + + class IndexBinary { + @injection def index: Index; + + @expname[faiss_index_binary_factory] + func new( + obj: ref[ref[IndexBinary]], + d: Int, + description: CharsPtr + ): Int; + + @expname[faiss_clone_index_binary] + func clone( + idx: ref[IndexBinary], + out: ref[ref[IndexBinary]] + ): Int; + + @expname[faiss_IndexBinary_free] + func free(obj: ref[IndexBinary]); + + @expname[faiss_IndexBinary_d] + handler this.d: Int; + + @expname[faiss_IndexBinary_is_trained] + handler this.isTrained: Int; + + @expname[faiss_IndexBinary_ntotal] + handler this.nTotal: Int[64]; + + @expname[faiss_IndexBinary_metric_type] + handler this.metricType: MetricType; + + @expname[faiss_IndexBinary_verbose] + handler this.verbose: Int; + + @expname[faiss_IndexBinary_set_verbose] + handler this.verbose = Int; + + @expname[faiss_IndexBinary_train] + handler this.train(n: Int[64], x: ref[array[Word[8]]]): Int; + + @expname[faiss_IndexBinary_add] + handler this.add(n: Int[64], x: ref[array[Word[8]]]): Int; + + @expname[faiss_IndexBinary_add_with_ids] + handler this.add( + n: Int[64], + x: ref[array[Word[64]]], + xids: ref[array[Int[64]]] + ): Int; + + @expname[faiss_IndexBinary_search] + handler this.search( + n: Int[64], + x: ref[array[Word[8]]], + k: Int[64], + distances: ref[array[Int]], + labels: ref[array[Int[64]]] + ): Int; + + @expname[faiss_IndexBinary_range_search] + handler this.search( + n: Int[64], + x: ref[array[Word[8]]], + radius: Int, + result: ref[RangeSearchResult] + ): Int; + + @expname[faiss_IndexBinary_assign] + func assign( + n: Int[64], + x: ref[array[Word[8]]], + labels: ref[array[Int[64]]], + k: Int[64] + ): Int; + + @expname[faiss_IndexBinary_reset] + handler this.reset(): Int; + + @expname[faiss_IndexBinary_remove_ids] + handler this.removeIds( + sel: ref[IdSelector], + nRemoved: ref[ArchWord] + ): Int; + + @expname[faiss_IndexBinary_reconstruct] + handler this.reconstruct( + key: Int[64], + recons: ref[array[Word[8]]] + ): Int; + + @expname[faiss_IndexBinary_reconstruct_n] + handler this.reconstruct( + i0: Int[64], + ni: Int[64], + recons: ref[array[Word[8]]] + ): Int; + } + + class IndexBinaryIvf { + @injection def indexBinary: IndexBinary; + + @expname[faiss_IndexBinaryIVF_free] + func free(obj: ref[IndexBinaryIvf]); + + @expname[faiss_IndexBinaryIVF_cast] + func cast(base: ref[IndexBinary]): ref[IndexBinaryIvf]; + + @expname[faiss_IndexBinaryIVF_nlist] + handler this.nList(): ArchWord; + + @expname[faiss_IndexBinaryIVF_nprobe] + handler this.nProbe(): ArchWord; + + @expname[faiss_IndexBinaryIVF_set_nprobe] + handler this.nProbe = ArchWord; + + @expname[faiss_IndexBinaryIVF_quantizer] + handler this.quantizer: ref[IndexBinary]; + + @expname[faiss_IndexBinaryIVF_own_fields] + handler this.ownFields: Int; + + @expname[faiss_IndexBinaryIVF_set_own_fields] + handler this.ownFields = Int; + + @expname[faiss_IndexBinaryIVF_max_codes] + handler this.maxCodes: ArchWord; + + @expname[faiss_IndexBinaryIVF_set_max_codes] + handler this.maxCodes = ArchWord + + @expname[faiss_IndexBinaryIVF_use_heap] + handler this.useHeap: Int; + + @expname[faiss_IndexBinaryIVF_set_use_heap] + handler this.useHeap = Int; + + @expname[faiss_IndexBinaryIVF_per_invlist_search] + handler this.perInvlistSearch: Int; + + @expname[faiss_IndexBinaryIVF_set_per_invlist_search] + handler this.perInvlistSearch = Int; + + @expname[faiss_IndexBinaryIVF_merge_from] + handler this.mergeFrom(other: ref[IndexBinaryIvf], addId: Int[64]): Int; + + @expname[faiss_IndexBinaryIVF_search_preassigned] + handler this.searchPreassigned( + n: Int[64], + x: ref[array[Word[8]]], + k: Int[64], + cidx: ref[array[Int[64]]], + cdis: ref[array[Int]], + dis: ref[array[Int]], + labels: ref[array[Int[64]]], + storePairs: Int, + params: ref[SearchParametersIvf] + ): Int; + + @expname[faiss_IndexBinaryIVF_get_list_size] + handler this.getListSize(listNo: ArchWord): ArchWord; + + + @expname[faiss_IndexBinaryIVF_make_direct_map] + handler this.makeDirectMap(newMaintainDirectMap: Int): Int; + + @expname[faiss_IndexBinaryIVF_imbalance_factor] + handler this.imbalanceFactor: Float[64]; + + @expname[faiss_IndexBinaryIVF_print_stats] + handler this.printStats(); + } + + class IndexFlat { + @injection def index: Index; + + @expname[faiss_IndexFlat_new] + func new(obj: ref[ref[IndexFlat]]): Int; + + @expname[faiss_IndexFlat_new_with] + func new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int; + + @expname[faiss_IndexFlat_cast] + func cast(base: ref[Index]): ref[IndexFlat]; + + @expname[faiss_IndexFlat_free] + func free(obj: ref[IndexFlat]); + + @expname[faiss_IndexFlat_xb] + handler this.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]); + + @expname[faiss_IndexFlat_compute_distance_subset] + handler this.computeDistanceSubset( + n: Int[64], + x: ref[array[Float]], + k: Int[64], + outDistances: ref[array[Float]], + labels: ref[array[Int[64]]] + ): Int; + } + + class IndexFlatIp { + @injection def index: Index; + + @expname[faiss_IndexFlatIP_new] + func new(obj: ref[ref[IndexFlatIp]]): Int; + + @expname[faiss_IndexFlatIP_new_with] + func new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int; + + @expname[faiss_IndexFlatIP_cast] + func cast(base: ref[Index]): ref[IndexFlatIp]; + + @expname[faiss_IndexFlatIP_free] + func free(obj: ref[IndexFlatIp]); + } + + class IndexFlatL2 { + @injection def index: Index; + + @expname[faiss_IndexFlatL2_new] + func new(obj: ref[ref[IndexFlatL2]]): Int; + + @expname[faiss_IndexFlatL2_new_with] + func faissIndexFlatL2NewWith(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int; + + @expname[faiss_IndexFlatL2_cast] + func cast(base: ref[Index]): ref[IndexFlatL2]; + + @expname[faiss_IndexFlatL2_free] + func free(obj: ref[IndexFlatL2]); + } + + class IndexRefineFlat { + @injection def index: Index; + + @expname[faiss_IndexRefineFlat_new] + func new(obj: ref[ref[IndexRefineFlat]], base: ref[Index]): Int; + + @expname[faiss_IndexRefineFlat_cast] + func cast(base: ref[Index]): ref[IndexRefineFlat]; + + @expname[faiss_IndexRefineFlat_free] + func free(obj: ref[IndexRefineFlat]); + + @expname[faiss_IndexRefineFlat_own_fields] + handler this.ownFields: Int; + + @expname[faiss_IndexRefineFlat_set_own_fields] + handler this.ownFields = Int; + + @expname[faiss_IndexRefineFlat_k_factor] + handler this.kFactor: Float; + + @expname[faiss_IndexRefineFlat_set_k_factor] + handler this.kFactor = Float; + } + + class IndexFlat1D { + @injection def index: Index; + + @expname[faiss_IndexFlat1D_new] + func new(obj: ref[ref[IndexFlat1D]]): Int; + + @expname[faiss_IndexFlat1D_new_with] + func new(obj: ref[ref[IndexFlat1D]], continuousUpdate: Int): Int; + + @expname[faiss_IndexFlat1D_cast] + func cast(base: ref[Index]): ref[IndexFlat1D]; + + @expname[faiss_IndexFlat1D_free] + func free( + obj: ref[IndexFlat1D] + ); + + @expname[faiss_IndexFlat1D_update_permutation] + handler this.updatePermutation(): Int; + } + + class IndexIvf { + @injection def index: Index; + + @expname[faiss_IndexIVF_free] + func free(obj: ref[IndexIvf]); + + @expname[faiss_IndexIVF_cast] + func cast(base: ref[Index]): ref[IndexIvf]; + + @expname[faiss_IndexIVF_nlist] + handler this.nList: ArchWord; + + @expname[faiss_IndexIVF_nprobe] + handler this.nProbe: ArchWord; + + @expname[faiss_IndexIVF_set_nprobe] + handler this.nProbe = ArchWord; + + @expname[faiss_IndexIVF_quantizer] + handler this.quantizer: ref[Index]; + + @expname[faiss_IndexIVF_quantizer_trains_alone] + handler this.quantizerTrainsAlone: Char; + + @expname[faiss_IndexIVF_own_fields] + handler this.ownFields: Int; + + @expname[faiss_IndexIVF_set_own_fields] + handler this.ownFields = Int; + + @expname[faiss_IndexIVF_merge_from] + handler this.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int; + + @expname[faiss_IndexIVF_copy_subset_to] + handler this.copySubsetTo( + other: ref[IndexIvf], + subsetType: Int, + a1: Int[64], + a2: Int[64] + ): Int; + + @expname[faiss_IndexIVF_search_preassigned] + handler this.searchPreassigned( + n: Int[64], + x: ref[array[Float]], + k: Int[64], + assign: ref[array[Int[64]]], + centroidDis: ref[array[Float]], + distances: ref[array[Float]], + labels: ref[array[Int[64]]], + storePairs: Int + ): Int; + + @expname[faiss_IndexIVF_get_list_size] + handler this.getListSize(listNo: ArchWord): ArchWord; + + @expname[faiss_IndexIVF_make_direct_map] + handler this.makeDirectMap(newMaintainDirectMap: Int): Int; + + @expname[faiss_IndexIVF_imbalance_factor] + handler this.imbalanceFactor: Float[64]; + + @expname[faiss_IndexIVF_print_stats] + handler this.printStats(); + + @expname[faiss_IndexIVF_invlists_get_ids] + handler this.getInvlistIds(listNo: ArchWord, invlist: ref[array[Int[64]]]); + + @expname[faiss_IndexIVF_train_encoder] + handler this.trainEncoder( + n: Int[64], + x: ref[array[Float]], + assign: ref[array[Int[64]]] + ): Int; + } + + class IndexIdMap { + @injection def index: Index; + + @expname[faiss_IndexIDMap_new] + func new(obj: ref[ref[IndexIdMap]],idx: ref[Index]): Int; + + @expname[faiss_IndexIDMap_cast] + func cast(base: ref[Index]): ref[IndexIdMap]; + + @expname[faiss_IndexIDMap_own_fields] + handler this.ownFields: Int; + + @expname[faiss_IndexIDMap_set_own_fields] + handler this.ownFields = Int; + + @expname[faiss_IndexIDMap_id_map] + handler this.getIdMap( + outMap: ref[ref[Int[64]]], + outSize: ref[ArchWord] + ); + + @expname[faiss_IndexIDMap_sub_index] + handler this.subIndex: ref[Index]; + } + + class IndexIdMap2 { + @injection def index: Index; + + @expname[faiss_IndexIDMap2_new] + func new(obj: ref[ref[IndexIdMap2]], idx: ref[Index]): Int; + + @expname[faiss_IndexIDMap2_cast] + func cast(base: ref[Index]): ref[IndexIdMap2]; + + @expname[faiss_IndexIDMap2_own_fields] + handler this.ownFields: Int; + + @expname[faiss_IndexIDMap2_set_own_fields] + handler this.ownFields = Int; + + @expname[faiss_IndexIDMap2_construct_rev_map] + handler this.constructRevMap(): Int; + + @expname[faiss_IndexIDMap2_id_map] + handler this.getIdMap( + outMap: ref[ref[Int[64]]], + outSize: ref[ArchWord] + ); + + @expname[faiss_IndexIDMap2_sub_index] + handler this.subIndex: ref[Index]; + } + + class IndexIvfStats { + def nq: ArchWord; + def nList: ArchWord; + def nDis: ArchWord; + def nHeapUpdates: ArchWord; + def quantizationTime: Float[64]; + def searchTime: Float[64]; + + @expname[faiss_IndexIVFStats_reset] + handler this.reset(); + } +} diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f288702..0000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/ParameterRange.alusus b/ParameterRange.alusus new file mode 100644 index 0000000..2b8b9b3 --- /dev/null +++ b/ParameterRange.alusus @@ -0,0 +1,12 @@ +@merge module Faiss { + class ParameterRange { + @expname[faiss_ParameterRange_name] + handler this.name: CharsPtr; + + @expname[faiss_ParameterRange_values] + handler this.getValues( + outValues: ref[ref[array[Float[64]]]], + outSize: ref[ArchWord] + ); + } +} diff --git a/ParameterSpace.alusus b/ParameterSpace.alusus new file mode 100644 index 0000000..a4ddfb1 --- /dev/null +++ b/ParameterSpace.alusus @@ -0,0 +1,47 @@ +@merge module Faiss { + class ParameterSpace { + @expname[faiss_ParameterSpace_new] + func new(obj: ref[ref[ParameterSpace]]): Int; + + @expname[faiss_ParameterSpace_free] + func free(obj: ref[ParameterSpace]); + + @expname[faiss_ParameterSpace_n_combinations] + handler this.nCombinations: ArchWord; + + @expname[faiss_ParameterSpace_combination_name] + handler this.getCombinationName( + combIndex: ArchWord, + outBuf: CharsPtr, + bufSize: ArchWord + ): Int; + + @expname[faiss_ParameterSpace_set_index_parameter] + handler this.setIndexParameter( + index: ref[Index], + paramName: CharsPtr, + val: Float[64] + ): Int; + + @expname[faiss_ParameterSpace_set_index_parameters] + handler this.setIndexParameters( + index: ref[Index], + params: CharsPtr + ): Int; + + @expname[faiss_ParameterSpace_set_index_parameters_cno] + handler this.seIndexParametersCno( + index: ref[Index], + val: ArchWord + ): Int; + + @expname[faiss_ParameterSpace_display] + handler this.display(); + + @expname[faiss_ParameterSpace_add_range] + handler this.addRange( + name: CharsPtr, + outRange: ref[ref[ParameterRange]] + ): Int; + } +} diff --git a/README.md b/README.md deleted file mode 100644 index 4d6a8d0..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Faiss -Alusus binding for Faiss library. diff --git a/RangeQueryResult.alusus b/RangeQueryResult.alusus new file mode 100644 index 0000000..0a0ef30 --- /dev/null +++ b/RangeQueryResult.alusus @@ -0,0 +1,18 @@ +@merge module Faiss { + class RangeQueryResult { + @expname[faiss_RangeQueryResult_add] + handler this.add( + dis: Float, + id: Int[64] + ): Int; + + @expname[faiss_RangeQueryResult_qno] + handler this.qno: Int[64]; + + @expname[faiss_RangeQueryResult_nres] + handler this.nres: ArchWord; + + @expname[faiss_RangeQueryResult_pres] + handler this.pres: ref[RangeSearchPartialResult]; + } +} diff --git a/RangeSearchPartialResult.alusus b/RangeSearchPartialResult.alusus new file mode 100644 index 0000000..9f05a12 --- /dev/null +++ b/RangeSearchPartialResult.alusus @@ -0,0 +1,24 @@ +@merge module Faiss { + class RangeSearchPartialResult { + @expname[faiss_RangeSearchPartialResult_new] + func new( + p_res: ref[ref[RangeSearchPartialResult]], + res_in: ref[RangeSearchResult] + ): Int; + + @expname[faiss_RangeSearchPartialResult_set_lims] + handler this.setLims(): Int; + + @expname[faiss_RangeSearchPartialResult_finalize] + handler this.finalize(): Int; + + @expname[faiss_RangeSearchPartialResult_new_result] + handler this.newResult( + qno: Int[64], + obj: ref[ref[RangeQueryResult]] + ): Int; + + @expname[faiss_RangeSearchPartialResult_res] + handler this.res: ref[RangeSearchResult]; + } +} diff --git a/RangeSearchResult.alusus b/RangeSearchResult.alusus new file mode 100644 index 0000000..72875e3 --- /dev/null +++ b/RangeSearchResult.alusus @@ -0,0 +1,41 @@ +@merge module Faiss { + class RangeSearchResult { + @expname[faiss_RangeSearchResult_new] + func new( + obj: ref[ref[RangeSearchResult]], + nq: Int[64] + ): Int; + + @expname[faiss_RangeSearchResult_new_with] + func new( + obj: ref[ref[RangeSearchResult]], + nq: Int[64], + allocLims: Int + ): Int; + + @expname[faiss_RangeSearchResult_free] + func free( + rsr: ref[RangeSearchResult] + ); + + @expname[faiss_RangeSearchResult_do_allocation] + handler this.doAllocation(): Int; + + @expname[faiss_RangeSearchResult_nq] + handler this.nq: Int[64]; + + @expname[faiss_RangeSearchResult_buffer_size] + handler this.bufferSize(): ArchWord; + + @expname[faiss_RangeSearchResult_lims] + handler this.getLims( + outLims: ref[ref[array[ArchWord]]] + ); + + @expname[faiss_RangeSearchResult_labels] + handler this.getLabels( + outLabels: ref[ref[array[Int[64]]]], + outDistances: ref[ref[ref[Float]]] + ); + } +} diff --git a/SearchParameters.alusus b/SearchParameters.alusus new file mode 100644 index 0000000..87397af --- /dev/null +++ b/SearchParameters.alusus @@ -0,0 +1,56 @@ +@merge module Faiss { + class SearchParameters { + @expname[faiss_SearchParameters_new] + func new( + obj: ref[ref[SearchParameters]], + sel: ref[IdSelector] + ): Int; + + @expname[faiss_SearchParameters_free] + func free(obj: ref[SearchParameters]); + + @expname[faiss_SearchParameters_nprobe] + handler this.nProbe: Int; + + @expname[faiss_SearchParameters_set_nprobe] + handler this.nProbe = Int; + } + + class SearchParametersIvf { + @injection def searchParameters: SearchParameters; + + @expname[faiss_SearchParametersIVF_new] + func new(obj: ref[ref[SearchParametersIvf]]): Int; + + @expname[faiss_SearchParametersIVF_new_with] + func new( + obj: ref[ref[SearchParametersIvf]], + sel: ref[IdSelector], + nprobe: ArchWord, + maxCodes: ArchWord + ): Int; + + @expname[faiss_SearchParametersIVF_free] + func free( + obj: ref[SearchParametersIvf] + ); + + @expname[faiss_SearchParametersIVF_cast] + func cast(base: ref[SearchParameters]): ref[SearchParametersIvf]; + + @expname[faiss_SearchParametersIVF_sel] + handler this.sel: ref[IdSelector]; + + @expname[faiss_SearchParametersIVF_nprobe] + handler this.nProbe: ArchWord; + + @expname[faiss_SearchParametersIVF_set_nprobe] + handler this.nProbe = ArchWord; + + @expname[faiss_SearchParametersIVF_max_codes] + handler this.maxCodes: ArchWord; + + @expname[faiss_SearchParametersIVF_set_max_codes] + handler this.maxCodes = ArchWord; + } +} diff --git a/license b/license new file mode 100644 index 0000000..fdb93fc --- /dev/null +++ b/license @@ -0,0 +1,31 @@ +MIT License + +Copyright (c) Facebook, Inc. and its affiliates. +Copyright (c) Alusus Software Ltd. for the Alusus language bindings. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--- + +This project contains Alusus language bindings for the FAISS library. + +FAISS (Facebook AI Similarity Search) is licensed under the MIT License. +Original FAISS repository: https://github.com/facebookresearch/faiss + +The Alusus language bindings are also licensed under the MIT License. diff --git a/readme.ar.md b/readme.ar.md new file mode 100644 index 0000000..80f32a8 --- /dev/null +++ b/readme.ar.md @@ -0,0 +1,851 @@ +
+ +# فـيس Faiss +[[English]](readme.md) + +روابط لغة الأسس لمكتبة [FAISS](https://github.com/facebookresearch/faiss) - مكتبة للبحث الفعّال عن التشابه وتجميع المتجهات الكثيفة. + +## نظرة عامة + +توفر هذه المكتبة روابط لغة الأسس لمكتبة FAISS، مما يتيح عمليات البحث عن التشابه في المتجهات والتجميع عالية الأداء في لغة الأسس. + +## التثبيت + +```alusus +اشمل "مـحا"؛ +مـحا.اشمل_ملف("Alusus/Faiss"، "فـيس.أسس")؛ +استخدم فـيس؛ +``` + +أو بالإنجليزية: + +
+ +```alusus +import "Apm"; +Apm.importFile("Alusus/Faiss"); +use Faiss; +``` + +
+ +## البدء السريع + +### مثال بالعربية + +```alusus +اشمل "مـتم/طـرفية"؛ +اشمل "مـتم/مـصفوفة"؛ +اشمل "مـحا"؛ +مـحا.اشمل_ملف("Alusus/Faiss"، "فـيس.أسس")؛ +استخدم مـتم؛ +استخدم فـيس؛ + +// إنشاء فهرس مسطح بمتجهات رباعية الأبعاد +عرف الفهرس: سند[فـهرس]؛ +فـهرس.أنشئ(الفهرس، 4، "Flat"، نـوع_قياس._نتاج_داخلي_)؛ + +// إضافة متجهات إلى الفهرس +عرف سب: مـصفوفة[عـائم]({1.0، 2.0، 3.0، 4.0، 2.0، 3.0، 4.0، 5.0})؛ +الفهرس.أضف(2، سب.صوان)؛ // متجهان + +// البحث عن أقرب الجيران +عرف سس: مـصفوفة[عـائم]({1.5، 2.5، 3.5، 4.5})؛ +عرف الوسوم: مصفوفة[صحيح[64]، 3]؛ +عرف المسافات: مصفوفة[عـائم، 3]؛ +الفهرس.ابحث(1، سس.صوان، 3، المسافات، الوسوم)؛ // البحث عن أقرب 3 جيران + +// التنظيف +فـهرس.حرر(الفهرس)؛ +``` + +### مثال بالإنجليزية + +
+ +```alusus +import "Srl/Console"; +import "Srl/Array"; +import "Apm"; +Apm.importFile("Alusus/Faiss"); +use Srl; +use Faiss; + +// Create a flat index with 4-dimensional vectors +def index: ref[Index]; +Index.new(index, 4, "Flat", MetricType.METRIC_INNER_PRODUCT); + +// Add vectors to the index +def xb: Array[Float]({1.0, 2.0, 3.0, 4.0, 2.0, 3.0, 4.0, 5.0}); +index.add(2, xb.buf); // 2 vectors + +// Search for nearest neighbors +def xq: Array[Float]({1.5, 2.5, 3.5, 4.5}); +def labels: array[Int[64], 3]; +def distances: array[Float, 3]; +index.search(1, xq.buf, 3, distances, labels); // Find 3 nearest neighbors + +// Clean up +Index.free(index); +``` + +
+ +انظر الأمثلة الكاملة في مجلد `Examples/`. + +## التوثيق + +تلتف هذه المكتبة حول واجهة FAISS البرمجية بلغة C. للحصول على توثيق مفصل حول المفاهيم والخوارزميات وأفضل الممارسات، يرجى الرجوع إلى التوثيق الرسمي لـ FAISS: + +- **التوثيق الرئيسي**: https://github.com/facebookresearch/faiss/wiki +- **مرجع واجهة C البرمجية**: https://github.com/facebookresearch/faiss/blob/main/c_api/ +- **دليل البدء**: https://github.com/facebookresearch/faiss/wiki/Getting-started +- **دليل اختيار الفهرس**: https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index + +## مرجع الواجهة البرمجية + +### الأصناف الأساسية + +#### فـهرس / Index +الصنف الرئيسي للبحث عن التشابه. [توثيق واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**دالة المصنع:** +- `أنشئ` / `new` + ```alusus + فـهرس.أنشئ(الكائن: سند[سند[فـهرس]]، ب: صـحيح، وصف: مـؤشر_محارف، نوع_القياس: صـحيح): صـحيح + ``` + +
+ + ```alusus + Index.new(obj: ref[ref[Index]]، d: Int، وصف: CharsPtr، metric: Int): Int + ``` + +
+ + إنشاء فهرس باستخدام نص المصنع + +**الدوال الرئيسية:** +- `درب` / `train` + ```alusus + فـهرس.درب(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح + ``` + +
+ + ```alusus + Index.train(n: Int[64]، x: ref[array[Float]]): Int + ``` + +
+ + تدريب الفهرس على البيانات + +- `أضف` / `add` + ```alusus + فـهرس.أضف(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح + ``` + +
+ + ```alusus + Index.add(n: Int[64]، x: ref[array[Float]]): Int + ``` + +
+ + إضافة متجهات إلى الفهرس + +- `ابحث` / `search` + ```alusus + فـهرس.ابحث(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، + مسافات: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]] + ): صـحيح + ``` + +
+ + ```alusus + Index.search(n: Int[64]، x: ref[array[Float]]، k: Int[64]، + distances: ref[array[Float]]، labels: ref[array[Int[64]]] + ): Int + ``` + +
+ + البحث عن k من أقرب الجيران + +- `بحث_المدى` / `rangeSearch` + ```alusus + فـهرس.بحث_المدى(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، radius: عـائم، + result: سند[نـتيجة_بحث_مدى]): صـحيح + ``` + +
+ + ```alusus + Index.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, + result: ref[RangeSearchResult]): Int + ``` + +
+ + البحث بنطاق + +- `أعد_الضبط` / `reset` + ```alusus + فـهرس.أعد_الضبط(): صـحيح + ``` + +
+ + ```alusus + Index.reset(): Int + ``` + +
+ + إزالة جميع المتجهات من الفهرس + +- `احذف_المعرفات` / `removeIds` + ```alusus + فـهرس.احذف_المعرفات(sel: سند[مـنتقي_معرف]، nRemoved: سند[كلمة_معمارية]): صـحيح + ``` + +
+ + ```alusus + Index.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int + ``` + +
+ + إزالة متجهات محددة + +**الخصائص:** +- `البعد` / `d`: `صحيح[64]` - بُعد المتجه +- `العدد_الكلي` / `nTotal`: `صحيح[64]` - العدد الإجمالي للمتجهات المفهرسة +- `مدرب` / `isTrained`: `صحيح` - ما إذا كان الفهرس مدرباً (0 أو 1) +- `نوع_القياس` / `metricType`: `نـوع_قياس` - مقياس المسافة المستخدم +- `إطناب` / `verbose`: `صحيح` - مستوى الإسهاب + +**التنظيف:** +- `حرر` / `free` + ```alusus + فـهرس.حرر(obj: سند[فـهرس]) + ``` + +
+ + ```alusus + Index.free(obj: ref[Index]) + ``` + +
+ + تحرير ذاكرة الفهرس + +#### فـهرس_مسطح / IndexFlat +فهرس القوة الغاشمة الذي يقوم بالبحث الدقيق. [دليل](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#flat-indexes) + +**الإنشاء:** +- `أنشئ` / `new` + ```alusus + فـهرس_مسطح.أنشئ(obj: سند[سند[فـهرس_مسطح]]): صـحيح + فـهرس_مسطح.أنشئ(obj: سند[سند[فـهرس_مسطح]]، d: صـحيح[64]، metric: نـوع_قياس): صـحيح + ``` + +
+ + ```alusus + IndexFlat.new(obj: ref[ref[IndexFlat]]): Int + IndexFlat.new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int + ``` + +
+ +**دوال إضافية:** +- `هات_البيانات` / `getXb` + ```alusus + فـهرس_مسطح.هات_البيانات(outXb: سند[سند[مصفوفة[عـائم]]]، outSize: سند[كلمة_معمارية]) + ``` + +
+ + ```alusus + IndexFlat.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) + ``` + +
+ + الحصول على المتجهات المخزنة + +- `احسب_مسافة_مجموعة_جزئية` / `computeDistanceSubset` + ```alusus + فـهرس_مسطح.احسب_مسافة_مجموعة_جزئية(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، + outDistances: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]]): صـحيح + ``` + +
+ + ```alusus + IndexFlat.computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64], + outDistances: ref[array[Float]], labels: ref[array[Int[64]]]): Int + ``` + +
+ + حساب المسافات إلى مجموعة جزئية + +يرث جميع دوال فـهرس / Index. + +#### فـهرس_مسطح_آيبي / IndexFlatIp +فهرس مسطح متخصص لمقياس الجداء الداخلي. [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) + +**الإنشاء:** +- `أنشئ` / `new` + ```alusus + فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]): صـحيح + فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]، d: صـحيح[64]): صـحيح + ``` + +
+ + ```alusus + IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int + IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int + ``` + +
+ +#### فـهرس_مسطح_ل2 / IndexFlatL2 +فهرس مسطح متخصص لمسافة L2 (إقليدس). [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) + +**الإنشاء:** +- `أنشئ` / `new` + ```alusus + فـهرس_مسطح_ل2.أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]): صـحيح + فـهرس_مسطح_ل2.أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]، d: صـحيح[64]): صـحيح + ``` + +
+ + ```alusus + IndexFlatL2.new(obj: ref[ref[IndexFlatL2]]): Int + IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int + ``` + +
+ +#### فـهرس_ملف_معكوس / IndexIvf +فهرس الملفات المعكوسة للبحث التقريبي الأسرع. [دليل](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#cell-probe-methods-indexivf-indexes) + +**خصائص إضافية:** +- `عدد_القوائم` / `nList`: `كلمة_معمارية` - عدد القوائم المعكوسة (العناقيد) +- `عدد_الاستقصاءات` / `nProbe`: `كلمة_معمارية` - عدد العناقيد المراد زيارتها أثناء البحث (قابل للضبط) +- `المكمم` / `quantizer`: `سند[فـهرس]` - فهرس المكمم +- `يمتلك_الحقول` / `ownFields`: `صحيح` - ما إذا كان الفهرس يمتلك حقوله + +**دوال إضافية:** +- `ادمج_من` / `mergeFrom` + ```alusus + فـهرس_ملف_معكوس.ادمج_من(other: سند[فـهرس_ملف_معكوس]، addId: صـحيح[64]): صـحيح + ``` + +
+ + ```alusus + IndexIvf.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int + ``` + +
+ + دمج فهرس IVF آخر + +- `انسخ_مجموعة_جزئية_إلى` / `copySubsetTo` + ```alusus + فـهرس_ملف_معكوس.انسخ_مجموعة_جزئية_إلى(other: سند[فـهرس_ملف_معكوس]، subsetType: صـحيح، a1: صـحيح[64]، a2: صـحيح[64]): صـحيح + ``` + +
+ + ```alusus + IndexIvf.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int + ``` + +
+ + نسخ مجموعة جزئية من المتجهات + +- `هات_حجم_القائمة` / `getListSize` + ```alusus + فـهرس_ملف_معكوس.هات_حجم_القائمة(listNo: كلمة_معمارية): كلمة_معمارية + ``` + +
+ + ```alusus + IndexIvf.getListSize(listNo: ArchWord): ArchWord + ``` + +
+ + الحصول على حجم القائمة المعكوسة + +- `اصنع_تعيينا_مباشرا` / `makeDirectMap` + ```alusus + فـهرس_ملف_معكوس.اصنع_تعيينا_مباشرا(newMaintainDirectMap: صـحيح): صـحيح + ``` + +
+ + ```alusus + IndexIvf.makeDirectMap(newMaintainDirectMap: Int): Int + ``` + +
+ + إنشاء خريطة مباشرة لإعادة البناء + +- `عامل_عدم_التوازن` / `imbalanceFactor`: `عـائم[64]` - الحصول على عامل عدم توازن العناقيد +- `اطبع_الإحصائيات` / `printStats`: `()` - طباعة إحصائيات الفهرس + +#### فـهرس_ثنائي / IndexBinary +فهرس للمتجهات الثنائية (هامينغ). [دليل](https://github.com/facebookresearch/faiss/wiki/Binary-indexes) + +مشابه لـ فـهرس / Index ولكنه يعمل على المتجهات الثنائية (مصفوفات Word[8] بدلاً من Float). + +### الأصناف الداعمة + +#### فـضاء_وسيط / ParameterSpace +إدارة معاملات الفهرس للبحث الشبكي والضبط. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/ParameterSpace_c.h) + +**الدوال:** +- `أنشئ` / `new` + ```alusus + فـضاء_وسيط.أنشئ(parameterSpace: سند[سند[فـضاء_وسيط]]): صـحيح + ``` + +
+ + ```alusus + ParameterSpace.new(parameterSpace: ref[ref[ParameterSpace]]): Int + ``` + +
+ +- `حدد_وسيط_فهرس` / `setIndexParameter` + ```alusus + فـضاء_وسيط.حدد_وسيط_فهرس(index: سند[فـهرس]، paramName: مـؤشر_محارف، val: عـائم[64]): صـحيح + ``` + +
+ + ```alusus + ParameterSpace.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int + ``` + +
+ + تعيين معامل واحد + +- `حدد_وسطاء_فهرس` / `setIndexParameters` + ```alusus + فـضاء_وسيط.حدد_وسطاء_فهرس(index: سند[فـهرس]، params: مـؤشر_محارف): صـحيح + ``` + +
+ + ```alusus + ParameterSpace.setIndexParameters(index: ref[Index], params: CharsPtr): Int + ``` + +
+ + تعيين معاملات متعددة + +- `أضف_مدى` / `addRange` + ```alusus + فـضاء_وسيط.أضف_مدى(name: مـؤشر_محارف، outRange: سند[سند[مـدى_وسيط]]): صـحيح + ``` + +
+ + ```alusus + ParameterSpace.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int + ``` + +
+ + إضافة نطاق معامل + +#### وسـطاء_بحث / SearchParameters +معاملات البحث في وقت التشغيل. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**الدوال:** +- `أنشئ` / `new` + ```alusus + وسـطاء_بحث.أنشئ(obj: سند[سند[وسـطاء_بحث]]، sel: سند[مـنتقي_معرف]): صـحيح + ``` + +
+ + ```alusus + SearchParameters.new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int + ``` + +
+ +- `عدد_الاستقصاءات` / `nProbe`: `صحيح` - عدد العناقيد المراد استقصاءها (لفهارس IVF) + +#### وسـطاء_بحث_ملف_معكوس / SearchParametersIvf +معاملات بحث موسعة لفهارس IVF. + +**الدوال:** +- `أنشئ` / `new` + ```alusus + وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]): صـحيح + وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]، sel: سند[مـنتقي_معرف]، + nprobe: كلمة_معمارية، maxCodes: كلمة_معمارية): صـحيح + ``` + +
+ + ```alusus + SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]]): Int + SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], + nprobe: ArchWord, maxCodes: ArchWord): Int + ``` + +
+ +**الخصائص:** +- `المنتقي` / `sel`: `سند[مـنتقي_معرف]` - منتقي المعرف +- `عدد_الاستقصاءات` / `nProbe`: `كلمة_معمارية` - عدد العناقيد المراد استقصاءها +- `أقصى_شفرات` / `maxCodes`: `كلمة_معمارية` - الحد الأقصى للشفرات المراد فحصها + +#### تـجميع / Clustering +تطبيق تجميع K-means. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Clustering_c.h) + +**الإنشاء:** +- `أنشئ` / `new` + ```alusus + تـجميع.أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح): صـحيح + تـجميع.أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح، params: مؤشر[وسـطاء_تجميع]): صـحيح + ``` + +
+ + ```alusus + Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int): Int + Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int + ``` + +
+ +**الدوال:** +- `درب` / `train` + ```alusus + تـجميع.درب(n: صـحيح[64]، x: سند[عـائم]، index: سند[فـهرس]): صـحيح + ``` + +
+ + ```alusus + Clustering.train(n: Int[64], x: ref[Float], index: ref[Index]): Int + ``` + +
+ + تشغيل k-means + +- `هات_المراكز` / `getCentroids` + ```alusus + تـجميع.هات_المراكز(centroids: سند[سند[مصفوفة[عـائم]]]، size: سند[كلمة_معمارية]) + ``` + +
+ + ```alusus + Clustering.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) + ``` + +
+ + الحصول على مراكز العناقيد + +- `هات_إحصائيات_الدورة` / `getIterationStats` + ```alusus + تـجميع.هات_إحصائيات_الدورة(stats_out: سند[سند[إحـصائيات_دورة_تجميع]]، size: سند[كلمة_معمارية]) + ``` + +
+ + ```alusus + Clustering.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) + ``` + +
+ + الحصول على إحصائيات التكرار + +**الخصائص:** +- `عدد_الدورات` / `niter`: `صحيح` - عدد التكرارات +- `عدد_الإعادات` / `nredo`: `صحيح` - عدد إعادات k-means +- `عدد_المراكز` / `k`: `كلمة_معمارية` - عدد العناقيد +- `البعد` / `d`: `كلمة_معمارية` - بُعد المتجه + +#### مـنتقي_معرف / IdSelector +اختيار مجموعات فرعية من المتجهات حسب المعرف. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**الأنواع:** +- `مـنتقي_معرف_حزمة` / `IdSelectorBatch` - اختيار معرفات محددة من قائمة +- `مـنتقي_معرف_مدى` / `IdSelectorRange` - اختيار المعرفات في نطاق +- `مـنتقي_معرف_بتماب` / `IdSelectorBitmap` - الاختيار باستخدام خريطة بت +- `مـنتقي_معرف_نفي` / `IdSelectorNot` - عكس منتقي +- `مـنتقي_معرف_و` / `IdSelectorAnd` - دمج المنتقيات بـ AND +- `مـنتقي_معرف_أو` / `IdSelectorOr` - دمج المنتقيات بـ OR +- `مـنتقي_معرف_أو_حصري` / `IdSelectorXor` - دمج المنتقيات بـ XOR + +#### نـتيجة_بحث_مدى / RangeSearchResult +نتائج استعلامات البحث بنطاق. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**الدوال:** +- `أنشئ` / `new` + ```alusus + نـتيجة_بحث_مدى.أنشئ(obj: سند[سند[نـتيجة_بحث_مدى]]، nq: صـحيح[64]): صـحيح + ``` + +
+ + ```alusus + RangeSearchResult.new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int + ``` + +
+ +- `نفذ_التخصيص` / `doAllocation` + ```alusus + نـتيجة_بحث_مدى.نفذ_التخصيص(): صـحيح + ``` + +
+ + ```alusus + RangeSearchResult.doAllocation(): Int + ``` + +
+ + تخصيص صوانات النتائج + +- `حجم_الصوان` / `bufferSize` + ```alusus + نـتيجة_بحث_مدى.حجم_الصوان(): كلمة_معمارية + ``` + +
+ + ```alusus + RangeSearchResult.bufferSize(): ArchWord + ``` + +
+ + الحصول على حجم الصوان + +- `هات_الحدود` / `getLims` + ```alusus + نـتيجة_بحث_مدى.هات_الحدود(outLims: سند[سند[مصفوفة[كلمة_معمارية]]]) + ``` + +
+ + ```alusus + RangeSearchResult.getLims(outLims: ref[ref[array[ArchWord]]]) + ``` + +
+ + الحصول على مصفوفة حدود النتائج + +- `هات_الوسوم` / `getLabels` + ```alusus + نـتيجة_بحث_مدى.هات_الوسوم(outLabels: سند[سند[مصفوفة[صـحيح[64]]]]، outDistances: سند[سند[سند[عـائم]]]) + ``` + +
+ + ```alusus + RangeSearchResult.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) + ``` + +
+ + الحصول على الوسوم والمسافات + +#### حـاسب_مسافة / DistanceComputer +حساب المسافات إلى المتجهات. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**الدوال:** +- `حدد_الاستعلام` / `setQuery` + ```alusus + حـاسب_مسافة.حدد_الاستعلام(x: سند[مصفوفة[عـائم]]): صـحيح + ``` + +
+ + ```alusus + DistanceComputer.setQuery(x: ref[array[Float]]): Int + ``` + +
+ + تعيين متجه الاستعلام + +- `مسافة_متجه_للاستعلام` / `vectorToQueryDis` + ```alusus + حـاسب_مسافة.مسافة_متجه_للاستعلام(i: صـحيح[64]، qd: سند[مصفوفة[عـائم]]): صـحيح + ``` + +
+ + ```alusus + DistanceComputer.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int + ``` + +
+ + المسافة إلى الاستعلام + +- `مسافة_متماثلة` / `symmetricDis` + ```alusus + حـاسب_مسافة.مسافة_متماثلة(i: صـحيح[64]، j: صـحيح[64]، vd: سند[مصفوفة[عـائم]]): صـحيح + ``` + +
+ + ```alusus + DistanceComputer.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int + ``` + +
+ + المسافة المتماثلة + +### الثوابت + +#### نـوع_قياس / MetricType +مقاييس المسافة. [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) + +- `_نتاج_داخلي_` / `METRIC_INNER_PRODUCT`: `0` - الجداء الداخلي (أقصى تشابه) +- `_ل2_` / `METRIC_L2`: `1` - المسافة الإقليدية (معيار L2) +- `_ل1_` / `METRIC_L1`: `2` - مسافة مانهاتن (معيار L1) +- `_ل8_` / `METRIC_LINF`: `3` - معيار اللانهاية (مسافة تشيبيشيف) +- `_لس_` / `METRIC_LP`: `4` - معيار Lp +- `_كانبيرا_` / `METRIC_CANBERRA`: `20` - مسافة كانبيرا +- `_براي_كرتس_` / `METRIC_BRAY_CURTIS`: `21` - تباين براي-كورتس +- `_جنسن_شانون_` / `METRIC_JENSEN_SHANNON`: `22` - تباعد جينسن-شانون + +#### رمـز_خطأ / ErrorCode +رموز الإرجاع من دوال واجهة C البرمجية. + +- `_نجاح_` / `OK`: `0` - نجاح +- `_استثناء_مجهول_` / `UNKNOWN_EXCEPT`: `-1` - استثناء غير معروف +- `_استثناء_فيس_` / `FAISS_EXCEPT`: `-2` - استثناء FAISS +- `_استثناء_قياسي_` / `STD_EXCEPT`: `-4` - استثناء المكتبة القياسية + +### الدوال + +- `هات_آخر_خطأ` / `getLastError` + ```alusus + فـيس.هات_آخر_خطأ(): مـؤشر_محارف + ``` + +
+ + ```alusus + Faiss.getLastError(): CharsPtr + ``` + +
+ + الحصول على رسالة الخطأ الأخيرة + +- `تجميع_كيمينز` / `kmeansClustering` + ```alusus + فـيس.تجميع_كيمينز(d: كلمة_معمارية، n: كلمة_معمارية، k: كلمة_معمارية، + x: سند[مصفوفة[عـائم]]، centroids: سند[مصفوفة[عـائم]]، q_error: سند[عـائم]): صـحيح + ``` + +
+ + ```alusus + Faiss.kmeansClustering(d: ArchWord, n: ArchWord, k: ArchWord, + x: ref[array[Float]], centroids: ref[array[Float]], q_error: ref[Float]): Int + ``` + +
+ + k-means مستقل + +## دعم GPU + +لتفعيل تسريع GPU، قم بتعيين متغير البيئة قبل التشغيل: +```bash +export FAISS_USE_GPU=1 +``` + +ستقوم المكتبة تلقائياً بتحميل الملفات الثنائية المفعّلة لـ GPU عند توفرها. راجع [توثيق FAISS GPU](https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU) للتفاصيل. + +## نصوص مصنع الفهرس + +تقبل دالة المصنع `أنشئ` / `new` نصوصاً لإنشاء أنواع فهرس مختلفة: + +- `"Flat"` - بحث دقيق (قوة غاشمة) +- `"IVFn,Flat"` - IVF مع n مركز، ترميز مسطح +- `"IVFn,PQm"` - IVF مع n مركز، PQ مع m مكمّم فرعي +- `"HNSW32"` - عالم صغير قابل للتنقل الهرمي مع 32 جار +- `"IVFn,HNSW32"` - IVF و HNSW مدمجان + +راجع [توثيق مصنع الفهرس](https://github.com/facebookresearch/faiss/wiki/The-index-factory) لجميع الخيارات والتوليفات المتاحة. + +## الأمثلة + +أمثلة عمل كاملة في مجلد `Examples/`: + +- **مثال.أسس** - فهرس مسطح أساسي مع بحث الجداء الداخلي (عربي) +- **مثال٢.أسس** - فهرس IVF مع ضبط المعاملات (عربي) +- **example.alusus** - فهرس مسطح أساسي مع بحث الجداء الداخلي (إنجليزي) +- **example2.alusus** - فهرس IVF مع ضبط المعاملات (إنجليزي) + +## نصائح الأداء + +1. **اختيار الفهرس**: + - استخدم `فـهرس_مسطح` / `IndexFlat` للبحث الدقيق في مجموعات البيانات <1 مليون متجه + - استخدم `فـهرس_ملف_معكوس` / `IndexIVF` للبحث التقريبي في مجموعات البيانات الأكبر + - راجع [دليل اختيار الفهرس](https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index) + +2. **التدريب**: تتطلب فهارس IVF والفهارس التقريبية الأخرى التدريب قبل إضافة المتجهات + +3. **معامل nprobe**: بالنسبة لفهارس IVF، nprobe أعلى = دقة أفضل ولكن بحث أبطأ + +4. **تسريع GPU**: فعّل GPU للعمليات على >10 مليون متجه + +5. **الذاكرة**: تخزّن الفهارس المسطحة جميع المتجهات في الذاكرة؛ استخدم الضغط لمجموعات البيانات الكبيرة + +راجع [إرشادات أداء FAISS](https://github.com/facebookresearch/faiss/wiki/Lower-memory-footprint) للتوصيات التفصيلية. + +## موارد إضافية + +- **FAISS على GitHub**: https://github.com/facebookresearch/faiss +- **ويكي FAISS**: https://github.com/facebookresearch/faiss/wiki +- **ورقة بحثية**: [البحث عن التشابه بمليارات المقاييس مع GPUs](https://arxiv.org/abs/1702.08734) +- **لغة الأسس**: https://alusus.org + +## الترخيص + +تتبع هذه الروابط ترخيص FAISS (MIT). راجع ملف `license` للتفاصيل. + +
+ diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4f6f1f6 --- /dev/null +++ b/readme.md @@ -0,0 +1,293 @@ +# Faiss +[[العربية]](readme.ar.md) + +Alusus language bindings for the [FAISS library](https://github.com/facebookresearch/faiss) - A library for efficient similarity search and clustering of dense vectors. + +## Overview + +This library provides Alusus bindings to FAISS, enabling high-performance vector similarity search and clustering operations in the Alusus programming language. + +## Installation + +```alusus +import "Apm"; +Apm.importFile("Alusus/Faiss"); +use Faiss; +``` + +## Quick Start + +```alusus +import "Srl/Console"; +import "Srl/Array"; +import "Apm"; +Apm.importFile("Alusus/Faiss"); +use Srl; +use Faiss; + +// Create a flat index with 4-dimensional vectors +def index: ref[Index]; +Index.new(index, 4, "Flat", MetricType.METRIC_INNER_PRODUCT); + +// Add vectors to the index +def xb: Array[Float]({1.0, 2.0, 3.0, 4.0, 2.0, 3.0, 4.0, 5.0}); +index.add(2, xb.buf); // 2 vectors + +// Search for nearest neighbors +def xq: Array[Float]({1.5, 2.5, 3.5, 4.5}); +def labels: array[Int[64], 3]; +def distances: array[Float, 3]; +index.search(1, xq.buf, 3, distances, labels); // Find 3 nearest neighbors + +// Clean up +Index.free(index); +``` + +See complete examples in the `Examples/` directory. + +## Documentation + +This library wraps the FAISS C API. For detailed documentation of concepts, algorithms, and best practices, please refer to the official FAISS documentation: + +- **Main Documentation**: https://github.com/facebookresearch/faiss/wiki +- **C API Reference**: https://github.com/facebookresearch/faiss/blob/main/c_api/ +- **Getting Started Tutorial**: https://github.com/facebookresearch/faiss/wiki/Getting-started +- **Index Selection Guide**: https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index + +## API Reference + +### Core Classes + +#### Index +Main index class for similarity search. [C API docs](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**Factory method:** +- `Index.new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int` - Create index using factory string + +**Key methods:** +- `train(n: Int[64], x: ref[array[Float]]): Int` - Train the index on data +- `add(n: Int[64], x: ref[array[Float]]): Int` - Add vectors to index +- `search(n: Int[64], x: ref[array[Float]], k: Int[64], distances: ref[array[Float]], labels: ref[array[Int[64]]]): Int` - Search for k nearest neighbors +- `rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int` - Range search +- `reset(): Int` - Remove all vectors from index +- `removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int` - Remove specific vectors + +**Properties:** +- `d: Int[64]` - Vector dimension +- `nTotal: Int[64]` - Total number of indexed vectors +- `isTrained: Int` - Whether index is trained (0 or 1) +- `metricType: MetricType` - Distance metric being used +- `verbose: Int` - Verbosity level + +**Cleanup:** +- `Index.free(obj: ref[Index])` - Free index memory + +#### IndexFlat +Brute-force index performing exact search. [Guide](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#flat-indexes) + +**Creation:** +- `IndexFlat.new(obj: ref[ref[IndexFlat]]): Int` +- `IndexFlat.new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int` + +**Additional methods:** +- `getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord])` - Get stored vectors +- `computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64], outDistances: ref[array[Float]], labels: ref[array[Int[64]]]): Int` - Compute distances to subset + +Inherits all Index methods. + +#### IndexFlatIp +Flat index specialized for inner product metric. [Docs](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) + +**Creation:** +- `IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int` +- `IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int` + +#### IndexFlatL2 +Flat index specialized for L2 (Euclidean) distance. [Docs](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) + +**Creation:** +- `IndexFlatL2.new(obj: ref[ref[IndexFlatL2]]): Int` +- `IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int` + +#### IndexIvf +Inverted file index for faster approximate search. [Guide](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#cell-probe-methods-indexivf-indexes) + +**Additional properties:** +- `nList: ArchWord` - Number of inverted lists (clusters) +- `nProbe: ArchWord` - Number of clusters to visit during search (tunable) +- `quantizer: ref[Index]` - Quantizer index +- `ownFields: Int` - Whether index owns its fields + +**Additional methods:** +- `mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int` - Merge another IVF index +- `copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int` - Copy subset of vectors +- `getListSize(listNo: ArchWord): ArchWord` - Get size of inverted list +- `makeDirectMap(newMaintainDirectMap: Int): Int` - Create direct map for reconstruction +- `imbalanceFactor: Float[64]` - Get cluster imbalance factor +- `printStats()` - Print index statistics + +#### IndexBinary +Index for binary (hamming) vectors. [Guide](https://github.com/facebookresearch/faiss/wiki/Binary-indexes) + +Similar to Index but operates on binary vectors (Word[8] arrays instead of Float arrays). + +### Support Classes + +#### ParameterSpace +Manages index parameters for grid search and tuning. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/ParameterSpace_c.h) + +**Methods:** +- `new(parameterSpace: ref[ref[ParameterSpace]]): Int` +- `setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int` - Set single parameter +- `setIndexParameters(index: ref[Index], params: CharsPtr): Int` - Set multiple parameters +- `addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int` - Add parameter range + +#### SearchParameters +Runtime search parameters. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**Methods:** +- `new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int` +- `nProbe: Int` - Number of clusters to probe (for IVF indexes) + +#### SearchParametersIvf +Extended search parameters for IVF indexes. + +**Methods:** +- `new(obj: ref[ref[SearchParametersIvf]]): Int` +- `new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int` + +**Properties:** +- `sel: ref[IdSelector]` - ID selector +- `nProbe: ArchWord` - Number of clusters to probe +- `maxCodes: ArchWord` - Maximum codes to scan + +#### Clustering +K-means clustering implementation. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Clustering_c.h) + +**Creation:** +- `new(out: ref[ref[Clustering]], d: Int, k: Int): Int` - Create with dimension and k clusters +- `new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int` - Create with parameters + +**Methods:** +- `train(n: Int[64], x: ref[Float], index: ref[Index]): Int` - Run k-means +- `getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord])` - Get cluster centroids +- `getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord])` - Get iteration statistics + +**Properties:** +- `niter: Int` - Number of iterations +- `nredo: Int` - Number of k-means restarts +- `k: ArchWord` - Number of clusters +- `d: ArchWord` - Vector dimension + +#### IdSelector +Select subsets of vectors by ID. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**Variants:** +- `IdSelectorBatch` - Select specific IDs from a list +- `IdSelectorRange` - Select IDs in a range +- `IdSelectorBitmap` - Select using a bitmap +- `IdSelectorNot` - Invert a selector +- `IdSelectorAnd` - Combine selectors with AND +- `IdSelectorOr` - Combine selectors with OR +- `IdSelectorXor` - Combine selectors with XOR + +#### RangeSearchResult +Results from range search queries. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**Methods:** +- `new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int` +- `doAllocation(): Int` - Allocate result buffers +- `bufferSize(): ArchWord` - Get buffer size +- `getLims(outLims: ref[ref[array[ArchWord]]])` - Get result limits array +- `getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]])` - Get labels and distances + +#### DistanceComputer +Compute distances to vectors. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) + +**Methods:** +- `setQuery(x: ref[array[Float]]): Int` - Set query vector +- `vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int` - Distance to query +- `symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int` - Symmetric distance + +### Constants + +#### MetricType +Distance metrics. [Docs](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) + +- `METRIC_INNER_PRODUCT: 0` - Inner product (maximum similarity) +- `METRIC_L2: 1` - Euclidean distance (L2 norm) +- `METRIC_L1: 2` - Manhattan distance (L1 norm) +- `METRIC_LINF: 3` - Infinity norm (Chebyshev distance) +- `METRIC_LP: 4` - Lp norm +- `METRIC_CANBERRA: 20` - Canberra distance +- `METRIC_BRAY_CURTIS: 21` - Bray-Curtis dissimilarity +- `METRIC_JENSEN_SHANNON: 22` - Jensen-Shannon divergence + +#### ErrorCode +Return codes from C API functions. + +- `OK: 0` - Success +- `UNKNOWN_EXCEPT: -1` - Unknown exception +- `FAISS_EXCEPT: -2` - FAISS exception +- `STD_EXCEPT: -4` - Standard library exception + +### Functions + +- `getLastError(): CharsPtr` - Get last error message +- `kmeansClustering(d: ArchWord, n: ArchWord, k: ArchWord, x: ref[array[Float]], centroids: ref[array[Float]], q_error: ref[Float]) Int` - Standalone k-means + +## GPU Support + +To enable GPU acceleration, set the environment variable before running: +```bash +export FAISS_USE_GPU=1 +``` + +The library will automatically load GPU-enabled binaries when available. See [FAISS GPU documentation](https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU) for details. + +## Index Factory Strings + +The `Index.new` factory method accepts strings to create different index types: + +- `"Flat"` - Exact search (brute force) +- `"IVFn,Flat"` - IVF with n centroids, flat encoding +- `"IVFn,PQm"` - IVF with n centroids, PQ with m subquantizers +- `"HNSW32"` - Hierarchical navigable small world with 32 neighbors +- `"IVFn,HNSW32"` - Combined IVF and HNSW + +See the [index factory documentation](https://github.com/facebookresearch/faiss/wiki/The-index-factory) for all available options and combinations. + +## Examples + +Complete working examples are in the `Examples/` directory: + +- **example.alusus** - Basic flat index with inner product search +- **example2.alusus** - IVF index with parameter tuning + +## Performance Tips + +1. **Index Selection**: + - Use `IndexFlat` for exact search on datasets <1M vectors + - Use `IndexIVF` for approximate search on larger datasets + - See the [index selection guide](https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index) + +2. **Training**: IVF and other approximate indexes require training before adding vectors + +3. **nprobe Parameter**: For IVF indexes, higher nprobe = better accuracy but slower search + +4. **GPU Acceleration**: Enable GPU for operations on >10M vectors + +5. **Memory**: Flat indexes store all vectors in memory; use compression for large datasets + +See [FAISS performance guidelines](https://github.com/facebookresearch/faiss/wiki/Lower-memory-footprint) for detailed recommendations. + +## Additional Resources + +- **FAISS GitHub**: https://github.com/facebookresearch/faiss +- **FAISS Wiki**: https://github.com/facebookresearch/faiss/wiki +- **Research Paper**: [Billion-scale similarity search with GPUs](https://arxiv.org/abs/1702.08734) +- **Alusus Language**: https://alusus.org + +## License + +This binding follows the FAISS license (MIT). See the `license` file for details. diff --git "a/\331\201\331\200\331\212\330\263.\330\243\330\263\330\263" "b/\331\201\331\200\331\212\330\263.\330\243\330\263\330\263" new file mode 100644 index 0000000..ae77e2c --- /dev/null +++ "b/\331\201\331\200\331\212\330\263.\330\243\330\263\330\263" @@ -0,0 +1,390 @@ +اشمل "Faiss"؛ + +عرف فـيس: لقب Faiss؛ +@دمج وحدة فـيس { + // الثوابت + + عرف رمـز_خطأ: { + عرف _نجاح_: لقب ErrorCode.OK؛ + عرف _استثناء_مجهول_: لقب ErrorCode.UNKNOWN_EXCEPT؛ + عرف _استثناء_فيس_: لقب ErrorCode.FAISS_EXCEPT؛ + عرف _استثناء_قياسي_: لقب ErrorCode.STD_EXCEPT؛ + } + + عرف نـوع_قياس: { + عرف _نتاج_داخلي_: لقب MetricType.INNER_PRODUCT؛ + عرف _ل2_: لقب MetricType.L2؛ + عرف _ل1_: لقب MetricType.L1؛ + عرف _ل8_: لقب MetricType.LINF؛ + عرف _لس_: لقب MetricType.LP؛ + عرف _كانبيرا_: لقب MetricType.CANBERRA؛ + عرف _براي_كرتس_: لقب MetricType.BRAY_CURTIS؛ + عرف _جنسن_شانون_: لقب MetricType.JENSEN_SHANNON؛ + } + + // الدوال الأساسية + + عرف هات_آخر_خطأ: لقب getLastError؛ + عرف تجميع_كيمينز: لقب kmeansClustering؛ + + // قائمة الصوانات + + عرف قـائمة_صوانات: لقب BufferList؛ + @دمج صنف قـائمة_صوانات { + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف ألحق_صوانا: لقب appendBuffer؛ + عرف أضف: لقب add؛ + عرف انسخ_مدى: لقب copyRange؛ + عرف حجم_الصوان: لقب bufferSize؛ + عرف مؤشر_الكتابة: لقب wp؛ + } + + // مدى وسيط + + عرف مـدى_وسيط: لقب ParameterRange؛ + @دمج صنف مـدى_وسيط { + عرف الاسم: لقب name؛ + عرف هات_القيم: لقب getValues؛ + } + + // فضاء المعامل + + عرف فـضاء_وسيط: لقب ParameterSpace؛ + @دمج صنف فـضاء_وسيط { + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف عدد_التوليفات: لقب nCombinations؛ + عرف هات_اسم_توليفة: لقب getCombinationName؛ + عرف حدد_وسيط_فهرس: لقب setIndexParameter؛ + عرف حدد_وسطاء_فهرس: لقب setIndexParameters؛ + عرف حدد_وسطاء_الفهرس_رقميا: لقب seIndexParametersCno؛ + عرف اعرض: لقب display؛ + عرف أضف_مدى: لقب addRange؛ + } + + // نتيجة استعلام المدى + + عرف نـتيجة_استعلام_مدى: لقب RangeQueryResult؛ + @دمج صنف نـتيجة_استعلام_مدى { + عرف أضف: لقب add؛ + عرف رقم_الاستعلام: لقب qno؛ + عرف عدد_النتائج: لقب nres؛ + عرف النتيجة_الجزئية: لقب pres؛ + } + + // نتيجة بحث المدى + + عرف نـتيجة_بحث_مدى: لقب RangeSearchResult؛ + @دمج صنف نـتيجة_بحث_مدى { + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف نفذ_التخصيص: لقب doAllocation؛ + عرف عدد_الاستعلامات: لقب nq؛ + عرف حجم_الصوان: لقب bufferSize؛ + عرف هات_الحدود: لقب getLims؛ + عرف هات_الوسوم: لقب getLabels؛ + } + + عرف نـتيجة_بحث_مدى_جزئية: لقب RangeSearchPartialResult؛ + @دمج صنف نـتيجة_بحث_مدى_جزئية { + عرف أنشئ: لقب new؛ + عرف حدد_الحدود: لقب setLims؛ + عرف أنه: لقب finalize؛ + عرف نتيجة_جديدة: لقب newResult؛ + عرف النتيجة: لقب res؛ + } + + // منتقي المعرف + + عرف مـنتقي_معرف: لقب IdSelector؛ + @دمج صنف مـنتقي_معرف { + عرف حرر: لقب free؛ + عرف أهو_عضو: لقب isMember؛ + } + + عرف مـنتقي_معرف_حزمة: لقب IdSelectorBatch؛ + @دمج صنف مـنتقي_معرف_حزمة { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف عدد_البتات: لقب nbits؛ + عرف القناع: لقب mask؛ + } + + عرف مـنتقي_معرف_بتماب: لقب IdSelectorBitmap؛ + @دمج صنف مـنتقي_معرف_بتماب { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف العدد: لقب n؛ + عرف الخريطة: لقب bitmap؛ + } + + عرف مـنتقي_معرف_مدى: لقب IdSelectorRange؛ + @دمج صنف مـنتقي_معرف_مدى { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف الحد_الأدنى: لقب imin؛ + عرف الحد_الأقصى: لقب imax؛ + } + + عرف مـنتقي_معرف_نفي: لقب IdSelectorNot؛ + @دمج صنف مـنتقي_معرف_نفي { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + } + + عرف مـنتقي_معرف_و: لقب IdSelectorAnd؛ + @دمج صنف مـنتقي_معرف_و { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + } + + عرف مـنتقي_معرف_أو: لقب IdSelectorOr؛ + @دمج صنف مـنتقي_معرف_أو { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + } + + عرف مـنتقي_معرف_أو_حصري: لقب IdSelectorXor؛ + @دمج صنف مـنتقي_معرف_أو_حصري { + عرف منتقي_المعرف: لقب idSelector؛ + عرف أنشئ: لقب new؛ + } + + // حاسب المسافة + + عرف حـاسب_مسافة: لقب DistanceComputer؛ + @دمج صنف حـاسب_مسافة { + عرف حدد_الاستعلام: لقب setQuery؛ + عرف مسافة_متجه_للاستعلام: لقب vectorToQueryDis؛ + عرف مسافة_متماثلة: لقب symmetricDis؛ + عرف حرر: لقب free؛ + } + + // التجميع + + عرف وسـطاء_تجميع: لقب ClusteringParameters؛ + @دمج صنف وسـطاء_تجميع { + عرف هيئ: لقب init؛ + } + + عرف إحـصائيات_دورة_تجميع: لقب ClusteringIterationStats؛ + @دمج صنف إحـصائيات_دورة_تجميع { + عرف الهدف: لقب obj؛ + عرف الوقت: لقب time؛ + عرف وقت_البحث: لقب timeSearch؛ + عرف عامل_عدم_التوازن: لقب imbalanceFactor؛ + عرف عدد_الانقسامات: لقب nSplit؛ + } + + عرف تـجميع: لقب Clustering؛ + @دمج صنف تـجميع { + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف عدد_الدورات: لقب nIter؛ + عرف عدد_الإعادات: لقب nRedo؛ + عرف إطناب: لقب verbose؛ + عرف كروي: لقب spherical؛ + عرف مراكز_صحيحة: لقب intCentroids؛ + عرف حدث_الفهرس: لقب updateIndex؛ + عرف مراكز_مجمدة: لقب frozenCentroids؛ + عرف أقل_نقاط_لكل_مركز: لقب minPointsPerCentroid؛ + عرف أكثر_نقاط_لكل_مركز: لقب maxPointsPerCentroid؛ + عرف البذرة: لقب seed؛ + عرف حجم_كتلة_فك_الترميز: لقب decodeBlockSize؛ + عرف البعد: لقب d؛ + عرف عدد_المراكز: لقب k؛ + عرف هات_المراكز: لقب getCentroids؛ + عرف هات_إحصائيات_الدورة: لقب getIterationStats؛ + عرف درب: لقب train؛ + } + + // الفهارس + + عرف فـهرس: لقب Index؛ + @دمج صنف فـهرس { + عرف أنشئ: لقب new؛ + عرف استنسخ: لقب clone؛ + عرف حرر: لقب free؛ + عرف البعد: لقب d؛ + عرف العدد_الكلي: لقب nTotal؛ + عرف مدرب: لقب isTrained؛ + عرف نوع_القياس: لقب metricType؛ + عرف إطناب: لقب verbose؛ + عرف درب: لقب train؛ + عرف أضف: لقب add؛ + عرف ابحث: لقب search؛ + عرف بحث_المدى: لقب rangeSearch؛ + عرف عين: لقب assign؛ + عرف أعد_الضبط: لقب reset؛ + عرف احذف_المعرفات: لقب removeIds؛ + عرف أعد_البناء: لقب reconstruct؛ + عرف احسب_المتبقي: لقب computeResidual؛ + عرف هات_حجم_الشفرة: لقب getSaCodeSize؛ + عرف رمز: لقب saEncode؛ + عرف فك_الترميز: لقب saDecode؛ + } + + عرف فـهرس_ثنائي: لقب IndexBinary؛ + @دمج صنف فـهرس_ثنائي { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف استنسخ: لقب clone؛ + عرف حرر: لقب free؛ + عرف البعد: لقب d؛ + عرف مدرب: لقب isTrained؛ + عرف العدد_الكلي: لقب nTotal؛ + عرف نوع_القياس: لقب metricType؛ + عرف إطناب: لقب verbose؛ + عرف درب: لقب train؛ + عرف أضف: لقب add؛ + عرف ابحث: لقب search؛ + عرف عين: لقب assign؛ + عرف أعد_الضبط: لقب reset؛ + عرف احذف_المعرفات: لقب removeIds؛ + عرف أعد_البناء: لقب reconstruct؛ + } + + عرف فـهرس_ثنائي_ملف_معكوس: لقب IndexBinaryIvf؛ + @دمج صنف فـهرس_ثنائي_ملف_معكوس { + عرف الفهرس_الثنائي: لقب indexBinary؛ + عرف حرر: لقب free؛ + عرف مثل: لقب cast؛ + عرف عدد_القوائم: لقب nList؛ + عرف عدد_الاستقصاءات: لقب nProbe؛ + عرف المكمم: لقب quantizer؛ + عرف يمتلك_الحقول: لقب ownFields؛ + عرف أقصى_شفرات: لقب maxCodes؛ + عرف استخدم_الكومة: لقب useHeap؛ + عرف بحث_لكل_قائمة_معكوسة: لقب perInvlistSearch؛ + عرف ادمج_من: لقب mergeFrom؛ + عرف ابحث_في_المحدد_مسبقا: لقب searchPreassigned؛ + عرف هات_حجم_القائمة: لقب getListSize؛ + عرف اصنع_تعيينا_مباشرا: لقب makeDirectMap؛ + عرف عامل_عدم_التوازن: لقب imbalanceFactor؛ + عرف اطبع_الإحصائيات: لقب printStats؛ + } + + عرف فـهرس_مسطح: لقب IndexFlat؛ + @دمج صنف فـهرس_مسطح { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف حرر: لقب free؛ + عرف هات_البيانات: لقب getXb؛ + عرف احسب_مسافة_مجموعة_جزئية: لقب computeDistanceSubset؛ + } + + عرف فـهرس_مسطح_آيبي: لقب IndexFlatIp؛ + @دمج صنف فـهرس_مسطح_آيبي { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف حرر: لقب free؛ + } + + عرف فـهرس_مسطح_ل2: لقب IndexFlatL2؛ + @دمج صنف فـهرس_مسطح_ل2 { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف حرر: لقب free؛ + } + + عرف فـهرس_تنقية_مسطح: لقب IndexRefineFlat؛ + @دمج صنف فـهرس_تنقية_مسطح { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف حرر: لقب free؛ + عرف يمتلك_الحقول: لقب ownFields؛ + عرف عامل_ك: لقب kFactor؛ + } + + عرف فـهرس_مسطح_أحادي_البعد: لقب IndexFlat1D؛ + @دمج صنف فـهرس_مسطح_أحادي_البعد { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف حرر: لقب free؛ + عرف حدث_التبديل: لقب updatePermutation؛ + } + + عرف فـهرس_ملف_معكوس: لقب IndexIvf؛ + @دمج صنف فـهرس_ملف_معكوس { + عرف الفهرس: لقب index؛ + عرف حرر: لقب free؛ + عرف مثل: لقب cast؛ + عرف عدد_القوائم: لقب nList؛ + عرف عدد_الاستقصاءات: لقب nProbe؛ + عرف المكمم: لقب quantizer؛ + عرف المكمم_يتدرب_وحيدا: لقب quantizerTrainsAlone؛ + عرف يمتلك_الحقول: لقب ownFields؛ + عرف ادمج_من: لقب mergeFrom؛ + عرف انسخ_مجموعة_جزئية_إلى: لقب copySubsetTo؛ + عرف ابحث_في_المحدد_مسبقا: لقب searchPreassigned؛ + عرف هات_حجم_القائمة: لقب getListSize؛ + عرف اصنع_تعيينا_مباشرا: لقب makeDirectMap؛ + عرف عامل_عدم_التوازن: لقب imbalanceFactor؛ + عرف اطبع_الإحصائيات: لقب printStats؛ + عرف أحضر_معرفات_القائمة_المعكوسة: لقب getInvlistIds؛ + عرف درب_المرمز: لقب trainEncoder؛ + } + + عرف فـهرس_تعيين_معرفات: لقب IndexIdMap؛ + @دمج صنف فـهرس_تعيين_معرفات { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف يمتلك_الحقول: لقب ownFields؛ + عرف هات_تعيين_المعرفات: لقب getIdMap؛ + عرف الفهرس_الفرعي: لقب subIndex؛ + } + + عرف فـهرس_تعيين_معرفات2: لقب IndexIdMap2؛ + @دمج صنف فـهرس_تعيين_معرفات2 { + عرف الفهرس: لقب index؛ + عرف أنشئ: لقب new؛ + عرف مثل: لقب cast؛ + عرف يمتلك_الحقول: لقب ownFields؛ + عرف اصنع_تعيينا_عكسيا: لقب constructRevMap؛ + عرف هات_تعيين_المعرفات: لقب getIdMap؛ + عرف الفهرس_الفرعي: لقب subIndex؛ + } + + // إحصائيات فهرس IVF + + عرف إـحصائيات_فهرس_ملف_معكوس: لقب IndexIvfStats؛ + @دمج صنف إـحصائيات_فهرس_ملف_معكوس { + عرف عدد_الاستعلامات: لقب nq؛ + عرف عدد_القوائم: لقب nList؛ + عرف عدد_المسافات: لقب nDis؛ + عرف عدد_تحديثات_الكومة: لقب nHeapUpdates؛ + عرف وقت_التكميم: لقب quantizationTime؛ + عرف وقت_البحث: لقب searchTime؛ + عرف أعد_الضبط: لقب reset؛ + } + + // وسطاء البحث + + عرف وسـطاء_بحث: لقب SearchParameters؛ + @دمج صنف وسـطاء_بحث { + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف عدد_الاستقصاءات: لقب nProbe؛ + } + + عرف وسـطاء_بحث_ملف_معكوس: لقب SearchParametersIvf؛ + @دمج صنف وسـطاء_بحث_ملف_معكوس { + عرف وسطاء_البحث: لقب searchParameters؛ + عرف أنشئ: لقب new؛ + عرف حرر: لقب free؛ + عرف مثل: لقب cast؛ + عرف المنتقي: لقب sel؛ + عرف عدد_الاستقصاءات: لقب nProbe؛ + عرف أقصى_شفرات: لقب maxCodes؛ + } +}