From 8eb5bf7a2b7750b67c937d5808ac78cd01bf2023 Mon Sep 17 00:00:00 2001 From: Hisham Mahgoub Date: Mon, 25 May 2026 23:44:47 +0300 Subject: [PATCH 1/3] changes on the english documentation structure --- README.md | 628 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 483 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index ed465aa..d109828 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,21 @@ # 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.importPackage("Alusus/Faiss@0.1"); use Faiss; @@ -17,7 +23,9 @@ use Faiss; ## Quick Start -```alusus + + +``` import "Srl/Console"; import "Srl/Array"; import "Apm"; @@ -47,201 +55,521 @@ 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 +* **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 + +### Index + Main index class for similarity search. [C API docs](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -**Static methods:** -- `Index.new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int` - Create index using factory string -- `Index.load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int` - Load index from a file -- `Index.save(obj: ref[Index], fname: CharsPtr): Int` - Save index to a file - -**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 +#### new + +``` +func Index.new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int +``` +Create index using factory string. + +#### load + +``` +func Index.load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int +``` +Load index from a file. + +#### save + +``` +func Index.save(obj: ref[Index], fname: CharsPtr): Int +``` +Save index to a file. + +#### train + +``` +func index.train(n: Int[64], x: ref[array[Float]]): Int +``` +Train the index on data. + +#### add + +``` +func index.add(n: Int[64], x: ref[array[Float]]): Int +``` +Add vectors to index. + +#### search + +``` +func 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 + +``` +func index.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int +``` +Range search. + +#### reset + +``` +func index.reset(): Int +``` +Remove all vectors from index. + +#### removeIds + +``` +func index.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int +``` +Remove specific vectors. + +#### d + +``` +index.d: Int[64] +``` +Vector dimension. + +#### nTotal + +``` +index.nTotal: Int[64] +``` +Total number of indexed vectors. + +#### isTrained + +``` +index.isTrained: Int +``` +Whether index is trained (0 or 1). + +#### metricType + +``` +index.metricType: MetricType +``` +Distance metric being used. + +#### verbose + +``` +index.verbose: Int +``` +Verbosity level. + +#### free + +``` +func 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` +#### new + +``` +func IndexFlat.new(obj: ref[ref[IndexFlat]]): Int +func IndexFlat.new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int +``` + +#### getXb + +``` +func indexFlat.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) +``` +Get stored vectors. -**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 +#### computeDistanceSubset + +``` +func indexFlat.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 +### 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` +#### new + +``` +func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int +func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int +``` + +### IndexFlatL2 -#### 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` +#### new + +``` +func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]]): Int +func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int +``` + +### IndexIvf -#### 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 +#### nList + +``` +indexIvf.nList: ArchWord +``` +Number of inverted lists (clusters). + +#### nProbe + +``` +indexIvf.nProbe: ArchWord +``` +Number of clusters to visit during search (tunable). + +#### quantizer + +``` +indexIvf.quantizer: ref[Index] +``` +Quantizer index. + +#### ownFields + +``` +indexIvf.ownFields: Int +``` +Whether index owns its fields. + +#### mergeFrom + +``` +func indexIvf.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int +``` +Merge another IVF index. + +#### copySubsetTo + +``` +func indexIvf.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int +``` +Copy subset of vectors. + +#### getListSize + +``` +func indexIvf.getListSize(listNo: ArchWord): ArchWord +``` +Get size of inverted list. + +#### makeDirectMap + +``` +func indexIvf.makeDirectMap(newMaintainDirectMap: Int): Int +``` +Create direct map for reconstruction. + +#### imbalanceFactor + +``` +indexIvf.imbalanceFactor: Float[64] +``` +Get cluster imbalance factor. + +#### printStats + +``` +func indexIvf.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 -#### 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 +#### new + +``` +func ParameterSpace.new(parameterSpace: ref[ref[ParameterSpace]]): Int +``` + +#### setIndexParameter + +``` +func parameterSpace.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int +``` +Set single parameter. + +#### setIndexParameters + +``` +func parameterSpace.setIndexParameters(index: ref[Index], params: CharsPtr): Int +``` +Set multiple parameters. + +#### addRange + +``` +func parameterSpace.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int +``` +Add parameter range. + +### SearchParameters -#### 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) +#### new + +``` +func SearchParameters.new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int +``` + +#### nProbe + +``` +searchParameters.nProbe: Int +``` +Number of clusters to probe (for IVF indexes). + +### SearchParametersIvf -#### 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` +#### new -**Properties:** -- `sel: ref[IdSelector]` - ID selector -- `nProbe: ArchWord` - Number of clusters to probe -- `maxCodes: ArchWord` - Maximum codes to scan +``` +func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]]): Int +func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int +``` + +#### sel + +``` +searchParametersIvf.sel: ref[IdSelector] +``` +ID selector. + +#### nProbe + +``` +searchParametersIvf.nProbe: ArchWord +``` +Number of clusters to probe. + +#### maxCodes + +``` +searchParametersIvf.maxCodes: ArchWord +``` +Maximum codes to scan. + +### Clustering -#### 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 +#### new + +``` +func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int): Int +func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int +``` +Create with dimension and k clusters. Second overload creates with parameters. + +#### train + +``` +func clustering.train(n: Int[64], x: ref[Float], index: ref[Index]): Int +``` +Run k-means. + +#### getCentroids + +``` +func clustering.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) +``` +Get cluster centroids. + +#### getIterationStats + +``` +func clustering.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) +``` +Get iteration statistics. + +#### niter + +``` +clustering.niter: Int +``` +Number of iterations. -**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 +#### nredo -**Properties:** -- `niter: Int` - Number of iterations -- `nredo: Int` - Number of k-means restarts -- `k: ArchWord` - Number of clusters -- `d: ArchWord` - Vector dimension +``` +clustering.nredo: Int +``` +Number of k-means restarts. + +#### k + +``` +clustering.k: ArchWord +``` +Number of clusters. + +#### d + +``` +clustering.d: ArchWord +``` +Vector dimension. + +### IdSelector -#### 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 +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 -#### 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 +#### new + +``` +func RangeSearchResult.new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int +``` + +#### doAllocation + +``` +func rangeSearchResult.doAllocation(): Int +``` +Allocate result buffers. + +#### bufferSize + +``` +func rangeSearchResult.bufferSize(): ArchWord +``` +Get buffer size. + +#### getLims + +``` +func rangeSearchResult.getLims(outLims: ref[ref[array[ArchWord]]]) +``` +Get result limits array. + +#### getLabels + +``` +func rangeSearchResult.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) +``` +Get labels and distances. + +### DistanceComputer -#### 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 +#### setQuery + +``` +func distanceComputer.setQuery(x: ref[array[Float]]): Int +``` +Set query vector. + +#### vectorToQueryDis + +``` +func distanceComputer.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int +``` +Distance to query. + +#### symmetricDis + +``` +func distanceComputer.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 +* `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 +* `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 +#### getLastError + +``` +func getLastError(): CharsPtr +``` +Get last error message. + +#### kmeansClustering + +``` +func 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 ``` @@ -249,29 +577,35 @@ The library will automatically load GPU-enabled binaries when available. See [FA ## 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 +* `"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 +* **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) + * 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 @@ -285,14 +619,18 @@ See [FAISS performance guidelines](https://github.com/facebookresearch/faiss/wik ## 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 + + +* **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 + + Copyright (c) Facebook, Inc. and its affiliates. Copyright (c) Alusus Software Ltd. for the Alusus language bindings. -This binding follows the FAISS license (MIT). See the `LICENSE` file for details. +This binding follows the FAISS license (MIT). See the `LICENSE` file for details. \ No newline at end of file From e802ae79d070f987c0adf39fe3e66b21cc9bceef Mon Sep 17 00:00:00 2001 From: Hisham Mahgoub Date: Sun, 31 May 2026 18:52:15 +0300 Subject: [PATCH 2/3] changes on the arabic documentation structure --- README.ar.md | 1163 +++++++++++++++++++++++++++++++------------------- 1 file changed, 734 insertions(+), 429 deletions(-) diff --git a/README.ar.md b/README.ar.md index 3eaaac3..a2ea16c 100644 --- a/README.ar.md +++ b/README.ar.md @@ -11,7 +11,7 @@ ## التثبيت -```alusus +``` اشمل "مـحا"؛ مـحا.اشمل_حزمة("Alusus/Faiss@0.1"، "فـيس.أسس")؛ استخدم فـيس؛ @@ -21,7 +21,7 @@
-```alusus +``` import "Apm"; Apm.importPackage("Alusus/Faiss@0.1"); use Faiss; @@ -33,7 +33,7 @@ use Faiss; ### مثال بالعربية -```alusus +``` اشمل "مـتم/طـرفية"؛ اشمل "مـتم/مـصفوفة"؛ اشمل "مـحا"؛ @@ -63,7 +63,7 @@ use Faiss;
-```alusus +``` import "Srl/Console"; import "Srl/Array"; import "Apm"; @@ -97,732 +97,1038 @@ Index.free(index); تلتف هذه المكتبة حول واجهة 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 +* **التوثيق الرئيسي**: 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 -#### فـهرس / Index الصنف الرئيسي للبحث عن التشابه. [توثيق واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -**الدوال الساكنة:** -- `أنشئ` / `new` - ```alusus - فـهرس.أنشئ(الكائن: سند[سند[فـهرس]]، ب: صـحيح، وصف: مـؤشر_محارف، نوع_القياس: صـحيح): صـحيح - ``` +#### أنشئ / new + +``` +فـهرس.أنشئ(الكائن: سند[سند[فـهرس]]، ب: صـحيح، وصف: مـؤشر_محارف، نوع_القياس: صـحيح): صـحيح +``` + +
+ +``` +func Index.new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int +``` + +
+ +إنشاء فهرس باستخدام نص المصنع. + +#### حمل / load + +``` +فـهرس.حمل(اسم_الملف: مـؤشر_محارف، خيارات: صـحيح، الكائن: سند[سند[فـهرس]]): صـحيح +``` + +
+ +``` +func Index.load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int +``` + +
+ +تحميل فهرس من ملف. + +#### احفظ / save + +``` +فـهرس.احفظ(الكائن: سند[فـهرس]، اسم_الملف: مـؤشر_محارف): صـحيح +``` + +
+ +``` +func Index.save(obj: ref[Index], fname: CharsPtr): Int +``` + +
+ +حفظ الفهرس إلى ملف. + +#### درب / train + +``` +فـهرس.درب(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح +``` + +
+ +``` +func index.train(n: Int[64], x: ref[array[Float]]): Int +``` + +
+ +تدريب الفهرس على البيانات. + +#### أضف / add + +``` +فـهرس.أضف(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح +``` + +
+ +``` +func index.add(n: Int[64], x: ref[array[Float]]): Int +``` + +
+ +إضافة متجهات إلى الفهرس. + +#### ابحث / search + +``` +فـهرس.ابحث(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، + مسافات: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]] + ): صـحيح +```
- ```alusus - Index.new(obj: ref[ref[Index]]، d: Int، وصف: CharsPtr، metric: Int): Int - ``` +``` +func index.search(n: Int[64], x: ref[array[Float]], k: Int[64], distances: ref[array[Float]], labels: ref[array[Int[64]]]): Int +```
- إنشاء فهرس باستخدام نص المصنع +البحث عن k من أقرب الجيران. -- `حمل` / `load` - ```alusus - فـهرس.حمل(اسم_الملف: مـؤشر_محارف، خيارات: صـحيح، الكائن: سند[سند[فـهرس]]): صـحيح - ``` +#### بحث_المدى / rangeSearch + +``` +فـهرس.بحث_المدى(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، radius: عـائم، + result: سند[نـتيجة_بحث_مدى]): صـحيح +```
- ```alusus - Index.load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int - ``` +``` +func index.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int +```
- تحميل فهرس من ملف +البحث بنطاق. + +#### أعد_الضبط / reset -- `احفظ` / `save` - ```alusus - فـهرس.احفظ(الكائن: سند[فـهرس]، اسم_الملف: مـؤشر_محارف): صـحيح - ``` +``` +فـهرس.أعد_الضبط(): صـحيح +```
- ```alusus - Index.save(obj: ref[Index], fname: CharsPtr): Int - ``` +``` +func index.reset(): Int +```
- حفظ الفهرس إلى ملف +إزالة جميع المتجهات من الفهرس. + +#### احذف_المعرفات / removeIds + +``` +فـهرس.احذف_المعرفات(sel: سند[مـنتقي_معرف]، nRemoved: سند[كلمة_معمارية]): صـحيح +``` -**الدوال الرئيسية:** -- `درب` / `train` - ```alusus - فـهرس.درب(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح - ``` -
- ```alusus - Index.train(n: Int[64]، x: ref[array[Float]]): Int - ``` +``` +func index.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int +```
- تدريب الفهرس على البيانات +إزالة متجهات محددة. + +#### البعد / d + +``` +البعد: صحيح[64] +``` -- `أضف` / `add` - ```alusus - فـهرس.أضف(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح - ``` -
- ```alusus - Index.add(n: Int[64]، x: ref[array[Float]]): Int - ``` +``` +index.d: Int[64] +```
- إضافة متجهات إلى الفهرس +بُعد المتجه. + +#### العدد_الكلي / nTotal + +``` +العدد_الكلي: صحيح[64] +``` -- `ابحث` / `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 - ``` +``` +index.nTotal: Int[64] +```
- البحث عن k من أقرب الجيران +العدد الإجمالي للمتجهات المفهرسة. -- `بحث_المدى` / `rangeSearch` - ```alusus - فـهرس.بحث_المدى(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، radius: عـائم، - result: سند[نـتيجة_بحث_مدى]): صـحيح - ``` +#### مدرب / isTrained + +``` +مدرب: صحيح +```
- ```alusus - Index.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, - result: ref[RangeSearchResult]): Int - ``` +``` +index.isTrained: Int +```
- البحث بنطاق +ما إذا كان الفهرس مدرباً (0 أو 1). -- `أعد_الضبط` / `reset` - ```alusus - فـهرس.أعد_الضبط(): صـحيح - ``` +#### نوع_القياس / metricType + +``` +نوع_القياس: نـوع_قياس +```
- ```alusus - Index.reset(): Int - ``` +``` +index.metricType: MetricType +```
- إزالة جميع المتجهات من الفهرس +مقياس المسافة المستخدم. -- `احذف_المعرفات` / `removeIds` - ```alusus - فـهرس.احذف_المعرفات(sel: سند[مـنتقي_معرف]، nRemoved: سند[كلمة_معمارية]): صـحيح - ``` +#### إطناب / verbose + +``` +إطناب: صحيح +```
- ```alusus - Index.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int - ``` +``` +index.verbose: Int +```
- إزالة متجهات محددة +مستوى الإسهاب. -**الخصائص:** -- `البعد` / `d`: `صحيح[64]` - بُعد المتجه -- `العدد_الكلي` / `nTotal`: `صحيح[64]` - العدد الإجمالي للمتجهات المفهرسة -- `مدرب` / `isTrained`: `صحيح` - ما إذا كان الفهرس مدرباً (0 أو 1) -- `نوع_القياس` / `metricType`: `نـوع_قياس` - مقياس المسافة المستخدم -- `إطناب` / `verbose`: `صحيح` - مستوى الإسهاب +#### حرر / free -**التنظيف:** -- `حرر` / `free` - ```alusus - فـهرس.حرر(obj: سند[فـهرس]) - ``` +``` +فـهرس.حرر(obj: سند[فـهرس]) +```
- ```alusus - Index.free(obj: ref[Index]) - ``` +``` +func Index.free(obj: ref[Index]) +```
- تحرير ذاكرة الفهرس +تحرير ذاكرة الفهرس. + +### فـهرس_مسطح / IndexFlat -#### فـهرس_مسطح / IndexFlat فهرس القوة الغاشمة الذي يقوم بالبحث الدقيق. [دليل](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#flat-indexes) -**الإنشاء:** -- `أنشئ` / `new` - ```alusus - فـهرس_مسطح.أنشئ(obj: سند[سند[فـهرس_مسطح]]): صـحيح - فـهرس_مسطح.أنشئ(obj: سند[سند[فـهرس_مسطح]]، d: صـحيح[64]، metric: نـوع_قياس): صـحيح - ``` +#### أنشئ / new + +``` +فـهرس_مسطح.أنشئ(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 - ``` +``` +func IndexFlat.new(obj: ref[ref[IndexFlat]]): Int +func IndexFlat.new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int +```
-**دوال إضافية:** -- `هات_البيانات` / `getXb` - ```alusus - فـهرس_مسطح.هات_البيانات(outXb: سند[سند[مصفوفة[عـائم]]]، outSize: سند[كلمة_معمارية]) - ``` +#### هات_البيانات / getXb + +``` +فـهرس_مسطح.هات_البيانات(outXb: سند[سند[مصفوفة[عـائم]]]، outSize: سند[كلمة_معمارية]) +```
- ```alusus - IndexFlat.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) - ``` +``` +func indexFlat.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) +```
- الحصول على المتجهات المخزنة +الحصول على المتجهات المخزنة. -- `احسب_مسافة_مجموعة_جزئية` / `computeDistanceSubset` - ```alusus - فـهرس_مسطح.احسب_مسافة_مجموعة_جزئية(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، - outDistances: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]]): صـحيح - ``` +#### احسب_مسافة_مجموعة_جزئية / computeDistanceSubset + +``` +فـهرس_مسطح.احسب_مسافة_مجموعة_جزئية(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 - ``` +``` +func indexFlat.computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64], outDistances: ref[array[Float]], labels: ref[array[Int[64]]]): Int +```
- حساب المسافات إلى مجموعة جزئية +حساب المسافات إلى مجموعة جزئية. يرث جميع دوال فـهرس / Index. -#### فـهرس_مسطح_آيبي / IndexFlatIp +### فـهرس_مسطح_آيبي / IndexFlatIp + فهرس مسطح متخصص لمقياس الجداء الداخلي. [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) -**الإنشاء:** -- `أنشئ` / `new` - ```alusus - فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]): صـحيح - فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]، d: صـحيح[64]): صـحيح - ``` +#### أنشئ / new + +``` +فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]): صـحيح +فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]، d: صـحيح[64]): صـحيح +```
- ```alusus - IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int - IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int - ``` +``` +func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int +func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int +```
-#### فـهرس_مسطح_ل2 / IndexFlatL2 +### فـهرس_مسطح_ل2 / IndexFlatL2 + فهرس مسطح متخصص لمسافة L2 (إقليدس). [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) -**الإنشاء:** -- `أنشئ` / `new` - ```alusus - فـهرس_مسطح_ل2.أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]): صـحيح - فـهرس_مسطح_ل2.أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]، d: صـحيح[64]): صـحيح - ``` +#### أنشئ / new + +``` +فـهرس_مسطح_ل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 - ``` +``` +func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]]): Int +func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int +```
-#### فـهرس_ملف_معكوس / IndexIvf +### فـهرس_ملف_معكوس / IndexIvf + فهرس الملفات المعكوسة للبحث التقريبي الأسرع. [دليل](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#cell-probe-methods-indexivf-indexes) -**خصائص إضافية:** -- `عدد_القوائم` / `nList`: `كلمة_معمارية` - عدد القوائم المعكوسة (العناقيد) -- `عدد_الاستقصاءات` / `nProbe`: `كلمة_معمارية` - عدد العناقيد المراد زيارتها أثناء البحث (قابل للضبط) -- `المكمم` / `quantizer`: `سند[فـهرس]` - فهرس المكمم -- `يمتلك_الحقول` / `ownFields`: `صحيح` - ما إذا كان الفهرس يمتلك حقوله +#### عدد_القوائم / nList + +``` +عدد_القوائم: كلمة_معمارية +``` + +
+ +``` +indexIvf.nList: ArchWord +``` + +
+ +عدد القوائم المعكوسة (العناقيد). + +#### عدد_الاستقصاءات / nProbe + +``` +عدد_الاستقصاءات: كلمة_معمارية +``` + +
+ +``` +indexIvf.nProbe: ArchWord +``` + +
+ +عدد العناقيد المراد زيارتها أثناء البحث (قابل للضبط). + +#### المكمم / quantizer + +``` +المكمم: سند[فـهرس] +``` + +
+ +``` +indexIvf.quantizer: ref[Index] +``` + +
+ +فهرس المكمم. + +#### يمتلك_الحقول / ownFields -**دوال إضافية:** -- `ادمج_من` / `mergeFrom` - ```alusus - فـهرس_ملف_معكوس.ادمج_من(other: سند[فـهرس_ملف_معكوس]، addId: صـحيح[64]): صـحيح - ``` +``` +يمتلك_الحقول: صحيح +```
- ```alusus - IndexIvf.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int - ``` +``` +indexIvf.ownFields: Int +``` + +
+ +ما إذا كان الفهرس يمتلك حقوله. + +#### ادمج_من / mergeFrom + +``` +فـهرس_ملف_معكوس.ادمج_من(other: سند[فـهرس_ملف_معكوس]، addId: صـحيح[64]): صـحيح +``` + +
+ +``` +func indexIvf.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int +``` + +
+ +دمج فهرس IVF آخر. + +#### انسخ_مجموعة_جزئية_إلى / copySubsetTo + +``` +فـهرس_ملف_معكوس.انسخ_مجموعة_جزئية_إلى(other: سند[فـهرس_ملف_معكوس]، subsetType: صـحيح، a1: صـحيح[64]، a2: صـحيح[64]): صـحيح +``` + +
+ +``` +func indexIvf.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int +``` + +
+ +نسخ مجموعة جزئية من المتجهات. + +#### هات_حجم_القائمة / getListSize + +``` +فـهرس_ملف_معكوس.هات_حجم_القائمة(listNo: كلمة_معمارية): كلمة_معمارية +``` + +
+ +``` +func indexIvf.getListSize(listNo: ArchWord): ArchWord +```
- دمج فهرس IVF آخر +الحصول على حجم القائمة المعكوسة. + +#### اصنع_تعيينا_مباشرا / makeDirectMap -- `انسخ_مجموعة_جزئية_إلى` / `copySubsetTo` - ```alusus - فـهرس_ملف_معكوس.انسخ_مجموعة_جزئية_إلى(other: سند[فـهرس_ملف_معكوس]، subsetType: صـحيح، a1: صـحيح[64]، a2: صـحيح[64]): صـحيح - ``` +``` +فـهرس_ملف_معكوس.اصنع_تعيينا_مباشرا(newMaintainDirectMap: صـحيح): صـحيح +```
- ```alusus - IndexIvf.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int - ``` +``` +func indexIvf.makeDirectMap(newMaintainDirectMap: Int): Int +```
- نسخ مجموعة جزئية من المتجهات +إنشاء خريطة مباشرة لإعادة البناء. + +#### عامل_عدم_التوازن / imbalanceFactor -- `هات_حجم_القائمة` / `getListSize` - ```alusus - فـهرس_ملف_معكوس.هات_حجم_القائمة(listNo: كلمة_معمارية): كلمة_معمارية - ``` +``` +عامل_عدم_التوازن: عـائم[64] +```
- ```alusus - IndexIvf.getListSize(listNo: ArchWord): ArchWord - ``` +``` +indexIvf.imbalanceFactor: Float[64] +```
- الحصول على حجم القائمة المعكوسة +الحصول على عامل عدم توازن العناقيد. -- `اصنع_تعيينا_مباشرا` / `makeDirectMap` - ```alusus - فـهرس_ملف_معكوس.اصنع_تعيينا_مباشرا(newMaintainDirectMap: صـحيح): صـحيح - ``` +#### اطبع_الإحصائيات / printStats + +``` +فـهرس_ملف_معكوس.اطبع_الإحصائيات() +```
- ```alusus - IndexIvf.makeDirectMap(newMaintainDirectMap: Int): Int - ``` +``` +func indexIvf.printStats() +```
- إنشاء خريطة مباشرة لإعادة البناء +طباعة إحصائيات الفهرس. -- `عامل_عدم_التوازن` / `imbalanceFactor`: `عـائم[64]` - الحصول على عامل عدم توازن العناقيد -- `اطبع_الإحصائيات` / `printStats`: `()` - طباعة إحصائيات الفهرس +### فـهرس_ثنائي / IndexBinary -#### فـهرس_ثنائي / IndexBinary فهرس للمتجهات الثنائية (هامينغ). [دليل](https://github.com/facebookresearch/faiss/wiki/Binary-indexes) مشابه لـ فـهرس / Index ولكنه يعمل على المتجهات الثنائية (مصفوفات Word[8] بدلاً من Float). -### الأصناف الداعمة +### فـضاء_وسيط / ParameterSpace -#### فـضاء_وسيط / ParameterSpace إدارة معاملات الفهرس للبحث الشبكي والضبط. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/ParameterSpace_c.h) -**الدوال:** -- `أنشئ` / `new` - ```alusus - فـضاء_وسيط.أنشئ(parameterSpace: سند[سند[فـضاء_وسيط]]): صـحيح - ``` +#### أنشئ / new + +``` +فـضاء_وسيط.أنشئ(parameterSpace: سند[سند[فـضاء_وسيط]]): صـحيح +```
- ```alusus - ParameterSpace.new(parameterSpace: ref[ref[ParameterSpace]]): Int - ``` +``` +func ParameterSpace.new(parameterSpace: ref[ref[ParameterSpace]]): Int +```
-- `حدد_وسيط_فهرس` / `setIndexParameter` - ```alusus - فـضاء_وسيط.حدد_وسيط_فهرس(index: سند[فـهرس]، paramName: مـؤشر_محارف، val: عـائم[64]): صـحيح - ``` +#### حدد_وسيط_فهرس / setIndexParameter + +``` +فـضاء_وسيط.حدد_وسيط_فهرس(index: سند[فـهرس]، paramName: مـؤشر_محارف، val: عـائم[64]): صـحيح +```
- ```alusus - ParameterSpace.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int - ``` +``` +func parameterSpace.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int +```
- تعيين معامل واحد +تعيين معامل واحد. -- `حدد_وسطاء_فهرس` / `setIndexParameters` - ```alusus - فـضاء_وسيط.حدد_وسطاء_فهرس(index: سند[فـهرس]، params: مـؤشر_محارف): صـحيح - ``` +#### حدد_وسطاء_فهرس / setIndexParameters + +``` +فـضاء_وسيط.حدد_وسطاء_فهرس(index: سند[فـهرس]، params: مـؤشر_محارف): صـحيح +```
- ```alusus - ParameterSpace.setIndexParameters(index: ref[Index], params: CharsPtr): Int - ``` +``` +func parameterSpace.setIndexParameters(index: ref[Index], params: CharsPtr): Int +```
- تعيين معاملات متعددة +تعيين معاملات متعددة. -- `أضف_مدى` / `addRange` - ```alusus - فـضاء_وسيط.أضف_مدى(name: مـؤشر_محارف، outRange: سند[سند[مـدى_وسيط]]): صـحيح - ``` +#### أضف_مدى / addRange + +``` +فـضاء_وسيط.أضف_مدى(name: مـؤشر_محارف، outRange: سند[سند[مـدى_وسيط]]): صـحيح +```
- ```alusus - ParameterSpace.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int - ``` +``` +func parameterSpace.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int +```
- إضافة نطاق معامل +إضافة نطاق معامل. + +### وسـطاء_بحث / SearchParameters -#### وسـطاء_بحث / SearchParameters معاملات البحث في وقت التشغيل. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -**الدوال:** -- `أنشئ` / `new` - ```alusus - وسـطاء_بحث.أنشئ(obj: سند[سند[وسـطاء_بحث]]، sel: سند[مـنتقي_معرف]): صـحيح - ``` +#### أنشئ / new + +``` +وسـطاء_بحث.أنشئ(obj: سند[سند[وسـطاء_بحث]]، sel: سند[مـنتقي_معرف]): صـحيح +```
- ```alusus - SearchParameters.new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int - ``` +``` +func SearchParameters.new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int +```
-- `عدد_الاستقصاءات` / `nProbe`: `صحيح` - عدد العناقيد المراد استقصاءها (لفهارس IVF) +#### عدد_الاستقصاءات / nProbe + +``` +عدد_الاستقصاءات: صحيح +``` + +
+ +``` +searchParameters.nProbe: Int +``` + +
+ +عدد العناقيد المراد استقصاءها (لفهارس IVF). + +### وسـطاء_بحث_ملف_معكوس / SearchParametersIvf -#### وسـطاء_بحث_ملف_معكوس / SearchParametersIvf معاملات بحث موسعة لفهارس IVF. -**الدوال:** -- `أنشئ` / `new` - ```alusus - وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]): صـحيح - وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]، sel: سند[مـنتقي_معرف]، - nprobe: كلمة_معمارية، maxCodes: كلمة_معمارية): صـحيح - ``` +#### أنشئ / new + +``` +وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]): صـحيح +وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]، sel: سند[مـنتقي_معرف]، + nprobe: كلمة_معمارية، maxCodes: كلمة_معمارية): صـحيح +``` + +
+ +``` +func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]]): Int +func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int +``` + +
+ +#### المنتقي / sel + +``` +المنتقي: سند[مـنتقي_معرف] +``` + +
+ +``` +searchParametersIvf.sel: ref[IdSelector] +``` + +
+ +منتقي المعرف. + +#### عدد_الاستقصاءات / nProbe + +``` +عدد_الاستقصاءات: كلمة_معمارية +```
- ```alusus - SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]]): Int - SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], - nprobe: ArchWord, maxCodes: ArchWord): Int - ``` +``` +searchParametersIvf.nProbe: ArchWord +```
-**الخصائص:** -- `المنتقي` / `sel`: `سند[مـنتقي_معرف]` - منتقي المعرف -- `عدد_الاستقصاءات` / `nProbe`: `كلمة_معمارية` - عدد العناقيد المراد استقصاءها -- `أقصى_شفرات` / `maxCodes`: `كلمة_معمارية` - الحد الأقصى للشفرات المراد فحصها +عدد العناقيد المراد استقصاءها. + +#### أقصى_شفرات / maxCodes + +``` +أقصى_شفرات: كلمة_معمارية +``` + +
+ +``` +searchParametersIvf.maxCodes: ArchWord +``` + +
+ +الحد الأقصى للشفرات المراد فحصها. + +### تـجميع / Clustering -#### تـجميع / 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: مؤشر[وسـطاء_تجميع]): صـحيح - ``` +#### أنشئ / new + +``` +تـجميع.أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح): صـحيح +تـجميع.أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح، params: مؤشر[وسـطاء_تجميع]): صـحيح +``` + +
+ +``` +func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int): Int +func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int +``` + +
+ +إنشاء بالبُعد وعدد العناقيد k. الصيغة الثانية تنشئ بمعاملات. + +#### درب / train + +``` +تـجميع.درب(n: صـحيح[64]، x: سند[عـائم]، index: سند[فـهرس]): صـحيح +``` + +
+ +``` +func clustering.train(n: Int[64], x: ref[Float], index: ref[Index]): Int +``` + +
+ +تشغيل k-means. + +#### هات_المراكز / getCentroids + +``` +تـجميع.هات_المراكز(centroids: سند[سند[مصفوفة[عـائم]]]، size: سند[كلمة_معمارية]) +```
- ```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 - ``` +``` +func clustering.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) +```
-**الدوال:** -- `درب` / `train` - ```alusus - تـجميع.درب(n: صـحيح[64]، x: سند[عـائم]، index: سند[فـهرس]): صـحيح - ``` +الحصول على مراكز العناقيد. + +#### هات_إحصائيات_الدورة / getIterationStats + +``` +تـجميع.هات_إحصائيات_الدورة(stats_out: سند[سند[إحـصائيات_دورة_تجميع]]، size: سند[كلمة_معمارية]) +```
- ```alusus - Clustering.train(n: Int[64], x: ref[Float], index: ref[Index]): Int - ``` +``` +func clustering.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) +```
- تشغيل k-means +الحصول على إحصائيات التكرار. + +#### عدد_الدورات / niter -- `هات_المراكز` / `getCentroids` - ```alusus - تـجميع.هات_المراكز(centroids: سند[سند[مصفوفة[عـائم]]]، size: سند[كلمة_معمارية]) - ``` +``` +عدد_الدورات: صحيح +```
- ```alusus - Clustering.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) - ``` +``` +clustering.niter: Int +```
- الحصول على مراكز العناقيد +عدد التكرارات. -- `هات_إحصائيات_الدورة` / `getIterationStats` - ```alusus - تـجميع.هات_إحصائيات_الدورة(stats_out: سند[سند[إحـصائيات_دورة_تجميع]]، size: سند[كلمة_معمارية]) - ``` +#### عدد_الإعادات / nredo + +``` +عدد_الإعادات: صحيح +```
- ```alusus - Clustering.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) - ``` +``` +clustering.nredo: Int +``` + +
+ +عدد إعادات k-means. + +#### عدد_المراكز / k + +``` +عدد_المراكز: كلمة_معمارية +``` + +
+ +``` +clustering.k: ArchWord +```
- الحصول على إحصائيات التكرار +عدد العناقيد. -**الخصائص:** -- `عدد_الدورات` / `niter`: `صحيح` - عدد التكرارات -- `عدد_الإعادات` / `nredo`: `صحيح` - عدد إعادات k-means -- `عدد_المراكز` / `k`: `كلمة_معمارية` - عدد العناقيد -- `البعد` / `d`: `كلمة_معمارية` - بُعد المتجه +#### البعد / d + +``` +البعد: كلمة_معمارية +``` + +
+ +``` +clustering.d: ArchWord +``` + +
+ +بُعد المتجه. + +### مـنتقي_معرف / IdSelector -#### مـنتقي_معرف / IdSelector اختيار مجموعات فرعية من المتجهات حسب المعرف. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -**الأنواع:** -- `مـنتقي_معرف_حزمة` / `IdSelectorBatch` - اختيار معرفات محددة من قائمة -- `مـنتقي_معرف_مدى` / `IdSelectorRange` - اختيار المعرفات في نطاق -- `مـنتقي_معرف_بتماب` / `IdSelectorBitmap` - الاختيار باستخدام خريطة بت -- `مـنتقي_معرف_نفي` / `IdSelectorNot` - عكس منتقي -- `مـنتقي_معرف_و` / `IdSelectorAnd` - دمج المنتقيات بـ AND -- `مـنتقي_معرف_أو` / `IdSelectorOr` - دمج المنتقيات بـ OR -- `مـنتقي_معرف_أو_حصري` / `IdSelectorXor` - دمج المنتقيات بـ XOR +الأنواع: +* `مـنتقي_معرف_حزمة` / `IdSelectorBatch`: اختيار معرفات محددة من قائمة +* `مـنتقي_معرف_مدى` / `IdSelectorRange`: اختيار المعرفات في نطاق +* `مـنتقي_معرف_بتماب` / `IdSelectorBitmap`: الاختيار باستخدام خريطة بت +* `مـنتقي_معرف_نفي` / `IdSelectorNot`: عكس منتقي +* `مـنتقي_معرف_و` / `IdSelectorAnd`: دمج المنتقيات بـ AND +* `مـنتقي_معرف_أو` / `IdSelectorOr`: دمج المنتقيات بـ OR +* `مـنتقي_معرف_أو_حصري` / `IdSelectorXor`: دمج المنتقيات بـ XOR + +### نـتيجة_بحث_مدى / RangeSearchResult -#### نـتيجة_بحث_مدى / RangeSearchResult نتائج استعلامات البحث بنطاق. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -**الدوال:** -- `أنشئ` / `new` - ```alusus - نـتيجة_بحث_مدى.أنشئ(obj: سند[سند[نـتيجة_بحث_مدى]]، nq: صـحيح[64]): صـحيح - ``` +#### أنشئ / new + +``` +نـتيجة_بحث_مدى.أنشئ(obj: سند[سند[نـتيجة_بحث_مدى]]، nq: صـحيح[64]): صـحيح +```
- ```alusus - RangeSearchResult.new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int - ``` +``` +func RangeSearchResult.new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int +```
-- `نفذ_التخصيص` / `doAllocation` - ```alusus - نـتيجة_بحث_مدى.نفذ_التخصيص(): صـحيح - ``` +#### نفذ_التخصيص / doAllocation + +``` +نـتيجة_بحث_مدى.نفذ_التخصيص(): صـحيح +```
- ```alusus - RangeSearchResult.doAllocation(): Int - ``` +``` +func rangeSearchResult.doAllocation(): Int +```
- تخصيص صوانات النتائج +تخصيص صوانات النتائج. -- `حجم_الصوان` / `bufferSize` - ```alusus - نـتيجة_بحث_مدى.حجم_الصوان(): كلمة_معمارية - ``` +#### حجم_الصوان / bufferSize + +``` +نـتيجة_بحث_مدى.حجم_الصوان(): كلمة_معمارية +```
- ```alusus - RangeSearchResult.bufferSize(): ArchWord - ``` +``` +func rangeSearchResult.bufferSize(): ArchWord +```
- الحصول على حجم الصوان +الحصول على حجم الصوان. + +#### هات_الحدود / getLims -- `هات_الحدود` / `getLims` - ```alusus - نـتيجة_بحث_مدى.هات_الحدود(outLims: سند[سند[مصفوفة[كلمة_معمارية]]]) - ``` +``` +نـتيجة_بحث_مدى.هات_الحدود(outLims: سند[سند[مصفوفة[كلمة_معمارية]]]) +```
- ```alusus - RangeSearchResult.getLims(outLims: ref[ref[array[ArchWord]]]) - ``` +``` +func rangeSearchResult.getLims(outLims: ref[ref[array[ArchWord]]]) +```
- الحصول على مصفوفة حدود النتائج +الحصول على مصفوفة حدود النتائج. + +#### هات_الوسوم / getLabels -- `هات_الوسوم` / `getLabels` - ```alusus - نـتيجة_بحث_مدى.هات_الوسوم(outLabels: سند[سند[مصفوفة[صـحيح[64]]]]، outDistances: سند[سند[سند[عـائم]]]) - ``` +``` +نـتيجة_بحث_مدى.هات_الوسوم(outLabels: سند[سند[مصفوفة[صـحيح[64]]]]، outDistances: سند[سند[سند[عـائم]]]) +```
- ```alusus - RangeSearchResult.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) - ``` +``` +func rangeSearchResult.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) +```
- الحصول على الوسوم والمسافات +الحصول على الوسوم والمسافات. + +### حـاسب_مسافة / DistanceComputer -#### حـاسب_مسافة / DistanceComputer حساب المسافات إلى المتجهات. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -**الدوال:** -- `حدد_الاستعلام` / `setQuery` - ```alusus - حـاسب_مسافة.حدد_الاستعلام(x: سند[مصفوفة[عـائم]]): صـحيح - ``` +#### حدد_الاستعلام / setQuery + +``` +حـاسب_مسافة.حدد_الاستعلام(x: سند[مصفوفة[عـائم]]): صـحيح +```
- ```alusus - DistanceComputer.setQuery(x: ref[array[Float]]): Int - ``` +``` +func distanceComputer.setQuery(x: ref[array[Float]]): Int +```
- تعيين متجه الاستعلام +تعيين متجه الاستعلام. -- `مسافة_متجه_للاستعلام` / `vectorToQueryDis` - ```alusus - حـاسب_مسافة.مسافة_متجه_للاستعلام(i: صـحيح[64]، qd: سند[مصفوفة[عـائم]]): صـحيح - ``` +#### مسافة_متجه_للاستعلام / vectorToQueryDis + +``` +حـاسب_مسافة.مسافة_متجه_للاستعلام(i: صـحيح[64]، qd: سند[مصفوفة[عـائم]]): صـحيح +```
- ```alusus - DistanceComputer.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int - ``` +``` +func distanceComputer.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int +```
- المسافة إلى الاستعلام +المسافة إلى الاستعلام. + +#### مسافة_متماثلة / symmetricDis -- `مسافة_متماثلة` / `symmetricDis` - ```alusus - حـاسب_مسافة.مسافة_متماثلة(i: صـحيح[64]، j: صـحيح[64]، vd: سند[مصفوفة[عـائم]]): صـحيح - ``` +``` +حـاسب_مسافة.مسافة_متماثلة(i: صـحيح[64]، j: صـحيح[64]، vd: سند[مصفوفة[عـائم]]): صـحيح +```
- ```alusus - DistanceComputer.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int - ``` +``` +func 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` - تباعد جينسن-شانون +* `_نتاج_داخلي_` / `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` - استثناء المكتبة القياسية +* `_نجاح_` / `OK` (`0`): نجاح +* `_استثناء_مجهول_` / `UNKNOWN_EXCEPT` (`-1`): استثناء غير معروف +* `_استثناء_فيس_` / `FAISS_EXCEPT` (`-2`): استثناء FAISS +* `_استثناء_قياسي_` / `STD_EXCEPT` (`-4`): استثناء المكتبة القياسية ### الدوال -- `هات_آخر_خطأ` / `getLastError` - ```alusus - فـيس.هات_آخر_خطأ(): مـؤشر_محارف - ``` +#### هات_آخر_خطأ / getLastError + +``` +فـيس.هات_آخر_خطأ(): مـؤشر_محارف +```
- ```alusus - Faiss.getLastError(): CharsPtr - ``` +``` +func getLastError(): CharsPtr +```
- الحصول على رسالة الخطأ الأخيرة +الحصول على رسالة الخطأ الأخيرة. -- `تجميع_كيمينز` / `kmeansClustering` - ```alusus - فـيس.تجميع_كيمينز(d: كلمة_معمارية، n: كلمة_معمارية، k: كلمة_معمارية، - x: سند[مصفوفة[عـائم]]، centroids: سند[مصفوفة[عـائم]]، q_error: سند[عـائم]): صـحيح - ``` +#### تجميع_كيمينز / kmeansClustering + +``` +فـيس.تجميع_كيمينز(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 - ``` +``` +func kmeansClustering(d: ArchWord, n: ArchWord, k: ArchWord, x: ref[array[Float]], centroids: ref[array[Float]], q_error: ref[Float]): Int +```
- k-means مستقل +k-means مستقل. ## دعم GPU لتفعيل تسريع GPU، قم بتعيين متغير البيئة قبل التشغيل: -```bash +``` export FAISS_USE_GPU=1 ``` @@ -830,13 +1136,13 @@ export FAISS_USE_GPU=1 ## نصوص مصنع الفهرس -تقبل دالة المصنع `أنشئ` / `new` نصوصاً لإنشاء أنواع فهرس مختلفة: +تقبل دالة المصنع `فـهرس.أنشئ` / `Index.new` نصوصاً لإنشاء أنواع فهرس مختلفة: -- `"Flat"` - بحث دقيق (قوة غاشمة) -- `"IVFn,Flat"` - IVF مع n مركز، ترميز مسطح -- `"IVFn,PQm"` - IVF مع n مركز، PQ مع m مكمّم فرعي -- `"HNSW32"` - عالم صغير قابل للتنقل الهرمي مع 32 جار -- `"IVFn,HNSW32"` - IVF و HNSW مدمجان +* `"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) لجميع الخيارات والتوليفات المتاحة. @@ -844,17 +1150,17 @@ export FAISS_USE_GPU=1 أمثلة عمل كاملة في مجلد `Examples/`: -- **مثال.أسس** - فهرس مسطح أساسي مع بحث الجداء الداخلي (عربي) -- **مثال٢.أسس** - فهرس IVF مع ضبط المعاملات (عربي) -- **example.alusus** - فهرس مسطح أساسي مع بحث الجداء الداخلي (إنجليزي) -- **example2.alusus** - فهرس IVF مع ضبط المعاملات (إنجليزي) +* **مثال.أسس**: فهرس مسطح أساسي مع بحث الجداء الداخلي (عربي) +* **مثال٢.أسس**: فهرس IVF مع ضبط المعاملات (عربي) +* **example.alusus**: فهرس مسطح أساسي مع بحث الجداء الداخلي (إنجليزي) +* **example2.alusus**: فهرس IVF مع ضبط المعاملات (إنجليزي) ## نصائح الأداء 1. **اختيار الفهرس**: - - استخدم `فـهرس_مسطح` / `IndexFlat` للبحث الدقيق في مجموعات البيانات <1 مليون متجه - - استخدم `فـهرس_ملف_معكوس` / `IndexIVF` للبحث التقريبي في مجموعات البيانات الأكبر - - راجع [دليل اختيار الفهرس](https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index) + * استخدم `فـهرس_مسطح` / `IndexFlat` للبحث الدقيق في مجموعات البيانات <1 مليون متجه + * استخدم `فـهرس_ملف_معكوس` / `IndexIVF` للبحث التقريبي في مجموعات البيانات الأكبر + * راجع [دليل اختيار الفهرس](https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index) 2. **التدريب**: تتطلب فهارس IVF والفهارس التقريبية الأخرى التدريب قبل إضافة المتجهات @@ -868,14 +1174,13 @@ export FAISS_USE_GPU=1 ## موارد إضافية -- **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 على 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` للتفاصيل.
- From 167ac64fec1fd6cb4ddb8de26159738fa1eb854d Mon Sep 17 00:00:00 2001 From: Hisham Mahgoub Date: Thu, 4 Jun 2026 11:50:18 +0300 Subject: [PATCH 3/3] applyed some changes on the definitions structure so it follow the definitions strucutre applyed in other documents --- README.ar.md | 640 +++++++++++++++++++++++++-------------------------- README.md | 202 ++++++++-------- 2 files changed, 422 insertions(+), 420 deletions(-) diff --git a/README.ar.md b/README.ar.md index a2ea16c..0a7b4f8 100644 --- a/README.ar.md +++ b/README.ar.md @@ -1,6 +1,5 @@ -
- # فـيس Faiss + [[English]](README.md) روابط لغة الأسس لمكتبة [FAISS](https://github.com/facebookresearch/faiss) - مكتبة للبحث الفعّال عن التشابه وتجميع المتجهات الكثيفة. @@ -11,15 +10,17 @@ ## التثبيت +
+ ``` اشمل "مـحا"؛ مـحا.اشمل_حزمة("Alusus/Faiss@0.1"، "فـيس.أسس")؛ استخدم فـيس؛ ``` -أو بالإنجليزية: +
-
+أو بالإنجليزية: ``` import "Apm"; @@ -27,12 +28,12 @@ Apm.importPackage("Alusus/Faiss@0.1"); use Faiss; ``` -
- ## البدء السريع ### مثال بالعربية +
+ ``` اشمل "مـتم/طـرفية"؛ اشمل "مـتم/مـصفوفة"؛ @@ -59,9 +60,9 @@ use Faiss; فـهرس.حرر(الفهرس)؛ ``` -### مثال بالإنجليزية +
-
+### مثال بالإنجليزية ``` import "Srl/Console"; @@ -89,8 +90,6 @@ index.search(1, xq.buf, 3, distances, labels); // Find 3 nearest neighbors Index.free(index); ``` -
- انظر الأمثلة الكاملة في مجلد `Examples/`. ## التوثيق @@ -108,300 +107,308 @@ Index.free(index); الصنف الرئيسي للبحث عن التشابه. [توثيق واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) +**الأصناف الأساسية:** + #### أنشئ / new +
+ ``` -فـهرس.أنشئ(الكائن: سند[سند[فـهرس]]، ب: صـحيح، وصف: مـؤشر_محارف، نوع_القياس: صـحيح): صـحيح +دالة أنشئ(الكائن: سند[سند[فـهرس]]، ب: صـحيح، وصف: مـؤشر_محارف، نوع_القياس: صـحيح): صـحيح ``` -
+
``` -func Index.new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int +func new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int ``` -
- إنشاء فهرس باستخدام نص المصنع. #### حمل / load +
+ ``` -فـهرس.حمل(اسم_الملف: مـؤشر_محارف، خيارات: صـحيح، الكائن: سند[سند[فـهرس]]): صـحيح +دالة حمل(اسم_الملف: مـؤشر_محارف، خيارات: صـحيح، الكائن: سند[سند[فـهرس]]): صـحيح ``` -
+
``` -func Index.load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int +func load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int ``` -
- تحميل فهرس من ملف. #### احفظ / save +
+ ``` -فـهرس.احفظ(الكائن: سند[فـهرس]، اسم_الملف: مـؤشر_محارف): صـحيح +دالة احفظ(الكائن: سند[فـهرس]، اسم_الملف: مـؤشر_محارف): صـحيح ``` -
+
``` -func Index.save(obj: ref[Index], fname: CharsPtr): Int +func save(obj: ref[Index], fname: CharsPtr): Int ``` -
- حفظ الفهرس إلى ملف. -#### درب / train +#### حرر / free + +
+ +``` +دالة حرر(obj: سند[فـهرس]) +``` + +
``` -فـهرس.درب(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح +func free(obj: ref[Index]) ``` -
+تحرير ذاكرة الفهرس. + +**الدوال الرئيسية:** + +#### درب / train + +
``` -func index.train(n: Int[64], x: ref[array[Float]]): Int +عملية هذا.درب(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح ```
+``` +handler this.train(n: Int[64], x: ref[array[Float]]): Int +``` + تدريب الفهرس على البيانات. #### أضف / add +
+ ``` -فـهرس.أضف(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح +عملية هذا.أضف(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]): صـحيح ``` -
+
``` -func index.add(n: Int[64], x: ref[array[Float]]): Int +handler this.add(n: Int[64], x: ref[array[Float]]): Int ``` -
- إضافة متجهات إلى الفهرس. #### ابحث / search +
+ ``` -فـهرس.ابحث(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، +عملية هذا.ابحث(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، مسافات: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]] ): صـحيح ``` -
+
``` -func index.search(n: Int[64], x: ref[array[Float]], k: Int[64], distances: ref[array[Float]], labels: ref[array[Int[64]]]): Int +handler this.search(n: Int[64], x: ref[array[Float]], k: Int[64], distances: ref[array[Float]], labels: ref[array[Int[64]]]): Int ``` -
- البحث عن k من أقرب الجيران. #### بحث_المدى / rangeSearch +
+ ``` -فـهرس.بحث_المدى(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، radius: عـائم، - result: سند[نـتيجة_بحث_مدى]): صـحيح +عملية هذا.بحث_المدى(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، radius: عـائم، result: سند[نـتيجة_بحث_مدى]): صـحيح ``` -
+
``` -func index.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int +handler this.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int ``` -
- البحث بنطاق. #### أعد_الضبط / reset +
+ ``` -فـهرس.أعد_الضبط(): صـحيح +عملية هذا.أعد_الضبط(): صـحيح ``` -
+
``` -func index.reset(): Int +handler this.reset(): Int ``` -
- إزالة جميع المتجهات من الفهرس. #### احذف_المعرفات / removeIds +
+ ``` -فـهرس.احذف_المعرفات(sel: سند[مـنتقي_معرف]، nRemoved: سند[كلمة_معمارية]): صـحيح +عملية هذا.احذف_المعرفات(sel: سند[مـنتقي_معرف]، nRemoved: سند[طـبيعي_متكيف]): صـحيح ``` -
+
``` -func index.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int +handler this.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int ``` -
- إزالة متجهات محددة. +**الخصائص:** + #### البعد / d +
+ ``` البعد: صحيح[64] ``` -
+
``` -index.d: Int[64] +d: Int[64] ``` -
- بُعد المتجه. #### العدد_الكلي / nTotal +
+ ``` العدد_الكلي: صحيح[64] ``` -
+
``` -index.nTotal: Int[64] +nTotal: Int[64] ``` -
- العدد الإجمالي للمتجهات المفهرسة. #### مدرب / isTrained +
+ ``` مدرب: صحيح ``` -
+
``` -index.isTrained: Int +isTrained: Int ``` -
- ما إذا كان الفهرس مدرباً (0 أو 1). #### نوع_القياس / metricType +
+ ``` نوع_القياس: نـوع_قياس ``` -
+
``` -index.metricType: MetricType +metricType: MetricType ``` -
- مقياس المسافة المستخدم. #### إطناب / verbose -``` -إطناب: صحيح -``` - -
+
``` -index.verbose: Int +إطناب: صحيح ```
-مستوى الإسهاب. - -#### حرر / free - ``` -فـهرس.حرر(obj: سند[فـهرس]) +verbose: Int ``` -
- -``` -func Index.free(obj: ref[Index]) -``` - -
- -تحرير ذاكرة الفهرس. +مستوى الإسهاب. ### فـهرس_مسطح / IndexFlat فهرس القوة الغاشمة الذي يقوم بالبحث الدقيق. [دليل](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#flat-indexes) +**الإنشاء:** + #### أنشئ / new +
+ ``` -فـهرس_مسطح.أنشئ(obj: سند[سند[فـهرس_مسطح]]): صـحيح -فـهرس_مسطح.أنشئ(obj: سند[سند[فـهرس_مسطح]]، d: صـحيح[64]، metric: نـوع_قياس): صـحيح +دالة أنشئ(obj: سند[سند[فـهرس_مسطح]]): صـحيح +دالة أنشئ(obj: سند[سند[فـهرس_مسطح]]، d: صـحيح[64]، metric: نـوع_قياس): صـحيح ``` -
+
``` -func IndexFlat.new(obj: ref[ref[IndexFlat]]): Int -func IndexFlat.new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int +func new(obj: ref[ref[IndexFlat]]): Int +func new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int ``` -
+**دوال إضافية:** #### هات_البيانات / getXb +
+ ``` -فـهرس_مسطح.هات_البيانات(outXb: سند[سند[مصفوفة[عـائم]]]، outSize: سند[كلمة_معمارية]) +عملية هذا.هات_البيانات(outXb: سند[سند[مصفوفة[عـائم]]]، outSize: سند[طـبيعي_متكيف]) ``` -
+
``` -func indexFlat.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) +handler this.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) ``` -
- الحصول على المتجهات المخزنة. #### احسب_مسافة_مجموعة_جزئية / computeDistanceSubset +
+ ``` -فـهرس_مسطح.احسب_مسافة_مجموعة_جزئية(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، - outDistances: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]]): صـحيح +عملية هذا.احسب_مسافة_مجموعة_جزئية(n: صـحيح[64]، x: سند[مصفوفة[عـائم]]، k: صـحيح[64]، outDistances: سند[مصفوفة[عـائم]]، labels: سند[مصفوفة[صـحيح[64]]]): صـحيح ``` -
+
``` -func indexFlat.computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64], outDistances: ref[array[Float]], labels: ref[array[Int[64]]]): Int +handler this.computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64], outDistances: ref[array[Float]], labels: ref[array[Int[64]]]): Int ``` -
- حساب المسافات إلى مجموعة جزئية. يرث جميع دوال فـهرس / Index. @@ -410,56 +417,56 @@ func indexFlat.computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64 فهرس مسطح متخصص لمقياس الجداء الداخلي. [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) +**الإنشاء:** + #### أنشئ / new +
+ ``` -فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]): صـحيح -فـهرس_مسطح_آيبي.أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]، d: صـحيح[64]): صـحيح +دالة أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]): صـحيح +دالة أنشئ(obj: سند[سند[فـهرس_مسطح_آيبي]]، d: صـحيح[64]): صـحيح ``` -
+
``` func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int ``` -
- ### فـهرس_مسطح_ل2 / IndexFlatL2 فهرس مسطح متخصص لمسافة L2 (إقليدس). [توثيق](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) +**الإنشاء:** + #### أنشئ / new +
+ ``` -فـهرس_مسطح_ل2.أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]): صـحيح -فـهرس_مسطح_ل2.أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]، d: صـحيح[64]): صـحيح +دالة أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]): صـحيح +دالة أنشئ(obj: سند[سند[فـهرس_مسطح_ل2]]، d: صـحيح[64]): صـحيح ``` -
+
``` -func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]]): Int -func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int +func new(obj: ref[ref[IndexFlatL2]]): Int +func new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int ``` -
- ### فـهرس_ملف_معكوس / IndexIvf فهرس الملفات المعكوسة للبحث التقريبي الأسرع. [دليل](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#cell-probe-methods-indexivf-indexes) #### عدد_القوائم / nList -``` -عدد_القوائم: كلمة_معمارية -``` - -
+
``` -indexIvf.nList: ArchWord +عدد_القوائم: طـبيعي_متكيف ```
@@ -468,14 +475,10 @@ indexIvf.nList: ArchWord #### عدد_الاستقصاءات / nProbe -``` -عدد_الاستقصاءات: كلمة_معمارية -``` - -
+
``` -indexIvf.nProbe: ArchWord +عدد_الاستقصاءات: طـبيعي_متكيف ```
@@ -484,14 +487,10 @@ indexIvf.nProbe: ArchWord #### المكمم / quantizer -``` -المكمم: سند[فـهرس] -``` - -
+
``` -indexIvf.quantizer: ref[Index] +المكمم: سند[فـهرس] ```
@@ -500,114 +499,112 @@ indexIvf.quantizer: ref[Index] #### يمتلك_الحقول / ownFields -``` -يمتلك_الحقول: صحيح -``` - -
+
``` -indexIvf.ownFields: Int +يمتلك_الحقول: صحيح ```
ما إذا كان الفهرس يمتلك حقوله. +**دوال إضافية:** + #### ادمج_من / mergeFrom +
+ ``` -فـهرس_ملف_معكوس.ادمج_من(other: سند[فـهرس_ملف_معكوس]، addId: صـحيح[64]): صـحيح +عملية هذا.ادمج_من(other: سند[فـهرس_ملف_معكوس]، addId: صـحيح[64]): صـحيح ``` -
+
``` -func indexIvf.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int +handler this.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int ``` -
- دمج فهرس IVF آخر. #### انسخ_مجموعة_جزئية_إلى / copySubsetTo +
+ ``` -فـهرس_ملف_معكوس.انسخ_مجموعة_جزئية_إلى(other: سند[فـهرس_ملف_معكوس]، subsetType: صـحيح، a1: صـحيح[64]، a2: صـحيح[64]): صـحيح +عملية هذا.انسخ_مجموعة_جزئية_إلى(other: سند[فـهرس_ملف_معكوس]، subsetType: صـحيح، a1: صـحيح[64]، a2: صـحيح[64]): صـحيح ``` -
+
``` -func indexIvf.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int +handler this.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int ``` -
- نسخ مجموعة جزئية من المتجهات. #### هات_حجم_القائمة / getListSize +
+ ``` -فـهرس_ملف_معكوس.هات_حجم_القائمة(listNo: كلمة_معمارية): كلمة_معمارية +عملية هذا.هات_حجم_القائمة(listNo: طـبيعي_متكيف): طـبيعي_متكيف ``` -
+
``` -func indexIvf.getListSize(listNo: ArchWord): ArchWord +handler this.getListSize(listNo: ArchWord): ArchWord ``` -
- الحصول على حجم القائمة المعكوسة. #### اصنع_تعيينا_مباشرا / makeDirectMap +
+ ``` -فـهرس_ملف_معكوس.اصنع_تعيينا_مباشرا(newMaintainDirectMap: صـحيح): صـحيح +عملية هذا.اصنع_تعيينا_مباشرا(newMaintainDirectMap: صـحيح): صـحيح ``` -
+
``` -func indexIvf.makeDirectMap(newMaintainDirectMap: Int): Int +handler this.makeDirectMap(newMaintainDirectMap: Int): Int ``` -
- إنشاء خريطة مباشرة لإعادة البناء. #### عامل_عدم_التوازن / imbalanceFactor +
+ ``` -عامل_عدم_التوازن: عـائم[64] +عملية هذا.عامل_عدم_التوازن: عـائم[64] ``` -
+
``` -indexIvf.imbalanceFactor: Float[64] +handler this.imbalanceFactor: Float[64] ``` -
- الحصول على عامل عدم توازن العناقيد. #### اطبع_الإحصائيات / printStats +
+ ``` -فـهرس_ملف_معكوس.اطبع_الإحصائيات() +عملية هذا.اطبع_الإحصائيات() ``` -
+
``` -func indexIvf.printStats() +handler this.printStats() ``` -
- طباعة إحصائيات الفهرس. ### فـهرس_ثنائي / IndexBinary @@ -616,100 +613,104 @@ func indexIvf.printStats() مشابه لـ فـهرس / Index ولكنه يعمل على المتجهات الثنائية (مصفوفات Word[8] بدلاً من Float). +**الأصناف الداعمة** + ### فـضاء_وسيط / ParameterSpace إدارة معاملات الفهرس للبحث الشبكي والضبط. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/ParameterSpace_c.h) +**الدوال:** + #### أنشئ / new +
+ ``` -فـضاء_وسيط.أنشئ(parameterSpace: سند[سند[فـضاء_وسيط]]): صـحيح +دالة أنشئ(parameterSpace: سند[سند[فـضاء_وسيط]]): صـحيح ``` -
+
``` -func ParameterSpace.new(parameterSpace: ref[ref[ParameterSpace]]): Int +func new(parameterSpace: ref[ref[ParameterSpace]]): Int ``` -
- #### حدد_وسيط_فهرس / setIndexParameter +
+ ``` -فـضاء_وسيط.حدد_وسيط_فهرس(index: سند[فـهرس]، paramName: مـؤشر_محارف، val: عـائم[64]): صـحيح +عملية هذا.حدد_وسيط_فهرس(index: سند[فـهرس]، paramName: مـؤشر_محارف، val: عـائم[64]): صـحيح ``` -
+
``` -func parameterSpace.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int +handler this.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int ``` -
- تعيين معامل واحد. #### حدد_وسطاء_فهرس / setIndexParameters +
+ ``` -فـضاء_وسيط.حدد_وسطاء_فهرس(index: سند[فـهرس]، params: مـؤشر_محارف): صـحيح +عملية هذا.حدد_وسطاء_فهرس(index: سند[فـهرس]، params: مـؤشر_محارف): صـحيح ``` -
+
``` -func parameterSpace.setIndexParameters(index: ref[Index], params: CharsPtr): Int +handler this.setIndexParameters(index: ref[Index], params: CharsPtr): Int ``` -
- تعيين معاملات متعددة. #### أضف_مدى / addRange +
+ ``` -فـضاء_وسيط.أضف_مدى(name: مـؤشر_محارف، outRange: سند[سند[مـدى_وسيط]]): صـحيح +عملية هذا.أضف_مدى(name: مـؤشر_محارف، outRange: سند[سند[مـدى_وسيط]]): صـحيح ``` -
+
``` -func parameterSpace.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int +handler this.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int ``` -
- إضافة نطاق معامل. ### وسـطاء_بحث / SearchParameters معاملات البحث في وقت التشغيل. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) +**الدوال:** + #### أنشئ / new +
+ ``` -وسـطاء_بحث.أنشئ(obj: سند[سند[وسـطاء_بحث]]، sel: سند[مـنتقي_معرف]): صـحيح +دالة أنشئ(obj: سند[سند[وسـطاء_بحث]]، sel: سند[مـنتقي_معرف]): صـحيح ``` -
+
``` -func SearchParameters.new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int +func new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int ``` -
+**الخصائص:** #### عدد_الاستقصاءات / nProbe -``` -عدد_الاستقصاءات: صحيح -``` - -
+
``` -searchParameters.nProbe: Int +عدد_الاستقصاءات: صحيح ```
@@ -720,33 +721,32 @@ searchParameters.nProbe: Int معاملات بحث موسعة لفهارس IVF. +**الدوال:** + #### أنشئ / new +
+ ``` -وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]): صـحيح -وسـطاء_بحث_ملف_معكوس.أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]، sel: سند[مـنتقي_معرف]، - nprobe: كلمة_معمارية، maxCodes: كلمة_معمارية): صـحيح +دالة أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]): صـحيح +دالة أنشئ(obj: سند[سند[وسـطاء_بحث_ملف_معكوس]]، sel: سند[مـنتقي_معرف]،nprobe: طـبيعي_متكيف، maxCodes: طـبيعي_متكيف): صـحيح ``` -
+
``` -func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]]): Int -func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int +func new(obj: ref[ref[SearchParametersIvf]]): Int +func new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int ``` -
+**الخصائص:** #### المنتقي / sel -``` -المنتقي: سند[مـنتقي_معرف] -``` - -
+
``` -searchParametersIvf.sel: ref[IdSelector] +المنتقي: سند[مـنتقي_معرف] ```
@@ -755,14 +755,10 @@ searchParametersIvf.sel: ref[IdSelector] #### عدد_الاستقصاءات / nProbe -``` -عدد_الاستقصاءات: كلمة_معمارية -``` - -
+
``` -searchParametersIvf.nProbe: ArchWord +عدد_الاستقصاءات: طـبيعي_متكيف ```
@@ -771,14 +767,10 @@ searchParametersIvf.nProbe: ArchWord #### أقصى_شفرات / maxCodes -``` -أقصى_شفرات: كلمة_معمارية -``` - -
+
``` -searchParametersIvf.maxCodes: ArchWord +أقصى_شفرات: طـبيعي_متكيف ```
@@ -789,82 +781,84 @@ searchParametersIvf.maxCodes: ArchWord تطبيق تجميع K-means. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Clustering_c.h) +**الإنشاء:** + #### أنشئ / new +
+ ``` -تـجميع.أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح): صـحيح -تـجميع.أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح، params: مؤشر[وسـطاء_تجميع]): صـحيح +دالة أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح): صـحيح +دالة أنشئ(out: سند[سند[تـجميع]]، d: صـحيح، k: صـحيح، params: مؤشر[وسـطاء_تجميع]): صـحيح ``` -
+
``` -func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int): Int -func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int +func new(out: ref[ref[Clustering]], d: Int, k: Int): Int +func new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int ``` -
- إنشاء بالبُعد وعدد العناقيد k. الصيغة الثانية تنشئ بمعاملات. +**الدوال:** + #### درب / train +
+ ``` -تـجميع.درب(n: صـحيح[64]، x: سند[عـائم]، index: سند[فـهرس]): صـحيح +عملية هذا.درب(n: صـحيح[64]، x: سند[عـائم]، index: سند[فـهرس]): صـحيح ``` -
+
``` -func clustering.train(n: Int[64], x: ref[Float], index: ref[Index]): Int +handler this.train(n: Int[64], x: ref[Float], index: ref[Index]): Int ``` -
- تشغيل k-means. #### هات_المراكز / getCentroids +
+ ``` -تـجميع.هات_المراكز(centroids: سند[سند[مصفوفة[عـائم]]]، size: سند[كلمة_معمارية]) +عملية هذا.هات_المراكز(centroids: سند[سند[مصفوفة[عـائم]]]، size: سند[طـبيعي_متكيف]) ``` -
+
``` -func clustering.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) +handler this.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) ``` -
- الحصول على مراكز العناقيد. #### هات_إحصائيات_الدورة / getIterationStats +
+ ``` -تـجميع.هات_إحصائيات_الدورة(stats_out: سند[سند[إحـصائيات_دورة_تجميع]]، size: سند[كلمة_معمارية]) +عملية هذا.هات_إحصائيات_الدورة(stats_out: سند[سند[إحـصائيات_دورة_تجميع]]، size: سند[طـبيعي_متكيف]) ``` -
+
``` -func clustering.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) +handler this.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) ``` -
- الحصول على إحصائيات التكرار. -#### عدد_الدورات / niter +**الخصائص:** -``` -عدد_الدورات: صحيح -``` +#### عدد_الدورات / niter -
+
``` -clustering.niter: Int +عدد_الدورات: صحيح ```
@@ -873,14 +867,10 @@ clustering.niter: Int #### عدد_الإعادات / nredo -``` -عدد_الإعادات: صحيح -``` - -
+
``` -clustering.nredo: Int +عدد_الإعادات: صحيح ```
@@ -889,14 +879,10 @@ clustering.nredo: Int #### عدد_المراكز / k -``` -عدد_المراكز: كلمة_معمارية -``` - -
+
``` -clustering.k: ArchWord +عدد_المراكز: طـبيعي_متكيف ```
@@ -905,14 +891,10 @@ clustering.k: ArchWord #### البعد / d -``` -البعد: كلمة_معمارية -``` - -
+
``` -clustering.d: ArchWord +البعد: طـبيعي_متكيف ```
@@ -923,7 +905,7 @@ clustering.d: ArchWord اختيار مجموعات فرعية من المتجهات حسب المعرف. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -الأنواع: +**الأنواع:** * `مـنتقي_معرف_حزمة` / `IdSelectorBatch`: اختيار معرفات محددة من قائمة * `مـنتقي_معرف_مدى` / `IdSelectorRange`: اختيار المعرفات في نطاق * `مـنتقي_معرف_بتماب` / `IdSelectorBitmap`: الاختيار باستخدام خريطة بت @@ -936,134 +918,138 @@ clustering.d: ArchWord نتائج استعلامات البحث بنطاق. [واجهة C البرمجية](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) +**الدوال:** + #### أنشئ / new +
+ ``` -نـتيجة_بحث_مدى.أنشئ(obj: سند[سند[نـتيجة_بحث_مدى]]، nq: صـحيح[64]): صـحيح +دالة أنشئ(obj: سند[سند[نـتيجة_بحث_مدى]]، nq: صـحيح[64]): صـحيح ``` -
+
``` -func RangeSearchResult.new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int +func new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int ``` -
- #### نفذ_التخصيص / doAllocation +
+ ``` -نـتيجة_بحث_مدى.نفذ_التخصيص(): صـحيح +عملية هذا.نفذ_التخصيص(): صـحيح ``` -
+
``` -func rangeSearchResult.doAllocation(): Int +handler this.doAllocation(): Int ``` -
- تخصيص صوانات النتائج. #### حجم_الصوان / bufferSize +
+ ``` -نـتيجة_بحث_مدى.حجم_الصوان(): كلمة_معمارية +عملية هذا.حجم_الصوان(): طـبيعي_متكيف ``` -
+
``` -func rangeSearchResult.bufferSize(): ArchWord +handler this.bufferSize(): ArchWord ``` -
- الحصول على حجم الصوان. #### هات_الحدود / getLims +
+ ``` -نـتيجة_بحث_مدى.هات_الحدود(outLims: سند[سند[مصفوفة[كلمة_معمارية]]]) +عملية هذا.هات_الحدود(outLims: سند[سند[مصفوفة[طـبيعي_متكيف]]]) ``` -
+
``` -func rangeSearchResult.getLims(outLims: ref[ref[array[ArchWord]]]) +handler this.getLims(outLims: ref[ref[array[ArchWord]]]) ``` -
- الحصول على مصفوفة حدود النتائج. #### هات_الوسوم / getLabels +
+ ``` -نـتيجة_بحث_مدى.هات_الوسوم(outLabels: سند[سند[مصفوفة[صـحيح[64]]]]، outDistances: سند[سند[سند[عـائم]]]) +عملية هذا.هات_الوسوم(outLabels: سند[سند[مصفوفة[صـحيح[64]]]]، outDistances: سند[سند[سند[عـائم]]]) ``` -
+
``` -func rangeSearchResult.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) +handler this.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 +
+ ``` -حـاسب_مسافة.حدد_الاستعلام(x: سند[مصفوفة[عـائم]]): صـحيح +عملية هذا.حدد_الاستعلام(x: سند[مصفوفة[عـائم]]): صـحيح ``` -
+
``` -func distanceComputer.setQuery(x: ref[array[Float]]): Int +handler this.setQuery(x: ref[array[Float]]): Int ``` -
- تعيين متجه الاستعلام. #### مسافة_متجه_للاستعلام / vectorToQueryDis +
+ ``` -حـاسب_مسافة.مسافة_متجه_للاستعلام(i: صـحيح[64]، qd: سند[مصفوفة[عـائم]]): صـحيح +عملية هذا.مسافة_متجه_للاستعلام(i: صـحيح[64]، qd: سند[مصفوفة[عـائم]]): صـحيح ``` -
+
``` -func distanceComputer.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int +handler this.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int ``` -
- المسافة إلى الاستعلام. #### مسافة_متماثلة / symmetricDis +
+ ``` -حـاسب_مسافة.مسافة_متماثلة(i: صـحيح[64]، j: صـحيح[64]، vd: سند[مصفوفة[عـائم]]): صـحيح +عملية هذا.مسافة_متماثلة(i: صـحيح[64]، j: صـحيح[64]، vd: سند[مصفوفة[عـائم]]): صـحيح ``` -
+
``` -func distanceComputer.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int +handler this.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int ``` -
- المسافة المتماثلة. ### الثوابت @@ -1094,41 +1080,41 @@ func distanceComputer.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]] #### هات_آخر_خطأ / getLastError +
+ ``` -فـيس.هات_آخر_خطأ(): مـؤشر_محارف +دالة هات_آخر_خطأ(): مـؤشر_محارف ``` -
+
``` func getLastError(): CharsPtr ``` -
- الحصول على رسالة الخطأ الأخيرة. #### تجميع_كيمينز / kmeansClustering +
+ ``` -فـيس.تجميع_كيمينز(d: كلمة_معمارية، n: كلمة_معمارية، k: كلمة_معمارية، - x: سند[مصفوفة[عـائم]]، centroids: سند[مصفوفة[عـائم]]، q_error: سند[عـائم]): صـحيح +دالة تجميع_كيمينز(d: طـبيعي_متكيف، n: طـبيعي_متكيف، k: طـبيعي_متكيف، x: سند[مصفوفة[عـائم]]، centroids: سند[مصفوفة[عـائم]]، q_error: سند[عـائم]): صـحيح ``` -
+
``` func 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 ``` @@ -1182,5 +1168,3 @@ export FAISS_USE_GPU=1 ## الترخيص تتبع هذه الروابط ترخيص FAISS (MIT). راجع ملف `LICENSE` للتفاصيل. - -
diff --git a/README.md b/README.md index d109828..4c68661 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,14 @@ [[العربية]](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 - - ``` import "Apm"; Apm.importPackage("Alusus/Faiss@0.1"); @@ -23,8 +18,6 @@ use Faiss; ## Quick Start - - ``` import "Srl/Console"; import "Srl/Array"; @@ -55,8 +48,6 @@ 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 @@ -66,139 +57,147 @@ This library wraps the FAISS C API. For detailed documentation of concepts, algo ## API Reference - - ### Index Main index class for similarity search. [C API docs](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) +**Static methods:** + #### new ``` -func Index.new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int +func new(obj: ref[ref[Index]], d: Int, description: CharsPtr, metric: Int): Int ``` Create index using factory string. #### load ``` -func Index.load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int +func load(fname: CharsPtr, flags: Int, obj: ref[ref[Index]]): Int ``` Load index from a file. #### save ``` -func Index.save(obj: ref[Index], fname: CharsPtr): Int +func save(obj: ref[Index], fname: CharsPtr): Int ``` Save index to a file. +#### free + +``` +func free(obj: ref[Index]) +``` +Free index memory. + +**Key methods:** + #### train ``` -func index.train(n: Int[64], x: ref[array[Float]]): Int +handler this.train(n: Int[64], x: ref[array[Float]]): Int ``` Train the index on data. #### add ``` -func index.add(n: Int[64], x: ref[array[Float]]): Int +handler this.add(n: Int[64], x: ref[array[Float]]): Int ``` Add vectors to index. #### search ``` -func index.search(n: Int[64], x: ref[array[Float]], k: Int[64], distances: ref[array[Float]], labels: ref[array[Int[64]]]): Int +handler this.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 ``` -func index.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int +handler this.rangeSearch(n: Int[64], x: ref[array[Float]], radius: Float, result: ref[RangeSearchResult]): Int ``` Range search. #### reset ``` -func index.reset(): Int +handler this.reset(): Int ``` Remove all vectors from index. #### removeIds ``` -func index.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int +handler this.removeIds(sel: ref[IdSelector], nRemoved: ref[ArchWord]): Int ``` Remove specific vectors. +**Properties:** + #### d ``` -index.d: Int[64] +d: Int[64]; ``` Vector dimension. #### nTotal ``` -index.nTotal: Int[64] +nTotal: Int[64] ``` Total number of indexed vectors. #### isTrained ``` -index.isTrained: Int +isTrained: Int ``` Whether index is trained (0 or 1). #### metricType ``` -index.metricType: MetricType +metricType: MetricType ``` Distance metric being used. #### verbose ``` -index.verbose: Int +verbose: Int ``` Verbosity level. -#### free - -``` -func 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:** + #### new ``` -func IndexFlat.new(obj: ref[ref[IndexFlat]]): Int -func IndexFlat.new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int +func new(obj: ref[ref[IndexFlat]]): Int +func new(obj: ref[ref[IndexFlat]], d: Int[64], metric: MetricType): Int ``` +**Additional methods:** + #### getXb ``` -func indexFlat.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) +handler this.getXb(outXb: ref[ref[array[Float]]], outSize: ref[ArchWord]) ``` Get stored vectors. #### computeDistanceSubset ``` -func indexFlat.computeDistanceSubset(n: Int[64], x: ref[array[Float]], k: Int[64], outDistances: ref[array[Float]], labels: ref[array[Int[64]]]): Int +handler this.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. @@ -208,11 +207,13 @@ Inherits all Index methods. Flat index specialized for inner product metric. [Docs](https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances) +**Creation:** + #### new ``` -func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]]): Int -func IndexFlatIp.new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int +func new(obj: ref[ref[IndexFlatIp]]): Int +func new(obj: ref[ref[IndexFlatIp]], d: Int[64]): Int ``` ### IndexFlatL2 @@ -221,6 +222,8 @@ Flat index specialized for L2 (Euclidean) distance. [Docs](https://github.com/fa #### new +**Creation:** + ``` func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]]): Int func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int @@ -230,73 +233,77 @@ func IndexFlatL2.new(obj: ref[ref[IndexFlatL2]], d: Int[64]): Int Inverted file index for faster approximate search. [Guide](https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#cell-probe-methods-indexivf-indexes) +**Additional properties:** + #### nList ``` -indexIvf.nList: ArchWord +nList: ArchWord ``` Number of inverted lists (clusters). #### nProbe ``` -indexIvf.nProbe: ArchWord +nProbe: ArchWord ``` Number of clusters to visit during search (tunable). #### quantizer ``` -indexIvf.quantizer: ref[Index] +quantizer: ref[Index] ``` Quantizer index. #### ownFields ``` -indexIvf.ownFields: Int +ownFields: Int ``` Whether index owns its fields. +**Additional methods:** + #### mergeFrom ``` -func indexIvf.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int +handler this.mergeFrom(other: ref[IndexIvf], addId: Int[64]): Int ``` Merge another IVF index. #### copySubsetTo ``` -func indexIvf.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int +handler this.copySubsetTo(other: ref[IndexIvf], subsetType: Int, a1: Int[64], a2: Int[64]): Int ``` Copy subset of vectors. #### getListSize ``` -func indexIvf.getListSize(listNo: ArchWord): ArchWord +handler this.getListSize(listNo: ArchWord): ArchWord ``` Get size of inverted list. #### makeDirectMap ``` -func indexIvf.makeDirectMap(newMaintainDirectMap: Int): Int +handler this.makeDirectMap(newMaintainDirectMap: Int): Int ``` Create direct map for reconstruction. #### imbalanceFactor ``` -indexIvf.imbalanceFactor: Float[64] +handler this.imbalanceFactor: Float[64] ``` Get cluster imbalance factor. #### printStats ``` -func indexIvf.printStats() +handler this.printStats() ``` Print index statistics. @@ -306,34 +313,38 @@ Index for binary (hamming) vectors. [Guide](https://github.com/facebookresearch/ 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 ``` -func ParameterSpace.new(parameterSpace: ref[ref[ParameterSpace]]): Int +func new(parameterSpace: ref[ref[ParameterSpace]]): Int ``` #### setIndexParameter ``` -func parameterSpace.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int +handler this.setIndexParameter(index: ref[Index], paramName: CharsPtr, val: Float[64]): Int ``` Set single parameter. #### setIndexParameters ``` -func parameterSpace.setIndexParameters(index: ref[Index], params: CharsPtr): Int +handler this.setIndexParameters(index: ref[Index], params: CharsPtr): Int ``` Set multiple parameters. #### addRange ``` -func parameterSpace.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int +handler this.addRange(name: CharsPtr, outRange: ref[ref[ParameterRange]]): Int ``` Add parameter range. @@ -341,16 +352,20 @@ Add parameter range. Runtime search parameters. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) +**Methods:** + #### new ``` -func SearchParameters.new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int +func new(obj: ref[ref[SearchParameters]], sel: ref[IdSelector]): Int ``` +**Properties** + #### nProbe ``` -searchParameters.nProbe: Int +nProbe: Int ``` Number of clusters to probe (for IVF indexes). @@ -358,31 +373,35 @@ Number of clusters to probe (for IVF indexes). Extended search parameters for IVF indexes. +**Methods:** + #### new ``` -func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]]): Int -func SearchParametersIvf.new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int +func new(obj: ref[ref[SearchParametersIvf]]): Int +func new(obj: ref[ref[SearchParametersIvf]], sel: ref[IdSelector], nprobe: ArchWord, maxCodes: ArchWord): Int ``` +**Properties:** + #### sel ``` -searchParametersIvf.sel: ref[IdSelector] +sel: ref[IdSelector] ``` ID selector. #### nProbe ``` -searchParametersIvf.nProbe: ArchWord +nProbe: ArchWord ``` Number of clusters to probe. #### maxCodes ``` -searchParametersIvf.maxCodes: ArchWord +maxCodes: ArchWord ``` Maximum codes to scan. @@ -390,60 +409,69 @@ Maximum codes to scan. K-means clustering implementation. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Clustering_c.h) +**Creation:** + #### new ``` -func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int): Int -func Clustering.new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int +func new(out: ref[ref[Clustering]], d: Int, k: Int): Int + +func new(out: ref[ref[Clustering]], d: Int, k: Int, params: ptr[ClusteringParameters]): Int ``` -Create with dimension and k clusters. Second overload creates with parameters. +First form create with dimension and k clusters. + +Second form create with parameters. + +**Methods** #### train ``` -func clustering.train(n: Int[64], x: ref[Float], index: ref[Index]): Int +handler this.train(n: Int[64], x: ref[Float], index: ref[Index]): Int ``` Run k-means. #### getCentroids ``` -func clustering.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) +handler this.getCentroids(centroids: ref[ref[array[Float]]], size: ref[ArchWord]) ``` Get cluster centroids. #### getIterationStats ``` -func clustering.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) +handler this.getIterationStats(stats_out: ref[ref[ClusteringIterationStats]], size: ref[ArchWord]) ``` Get iteration statistics. +**Properties:** + #### niter ``` -clustering.niter: Int +niter: Int ``` Number of iterations. #### nredo ``` -clustering.nredo: Int +nredo: Int ``` Number of k-means restarts. #### k ``` -clustering.k: ArchWord +k: ArchWord ``` Number of clusters. #### d ``` -clustering.d: ArchWord +d: ArchWord ``` Vector dimension. @@ -451,7 +479,7 @@ Vector dimension. Select subsets of vectors by ID. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) -Variants: +**Variants:** * `IdSelectorBatch`: Select specific IDs from a list * `IdSelectorRange`: Select IDs in a range * `IdSelectorBitmap`: Select using a bitmap @@ -464,37 +492,39 @@ Variants: Results from range search queries. [C API](https://github.com/facebookresearch/faiss/blob/main/c_api/Index_c.h) +**Methods:** + #### new ``` -func RangeSearchResult.new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int +func new(obj: ref[ref[RangeSearchResult]], nq: Int[64]): Int ``` #### doAllocation ``` -func rangeSearchResult.doAllocation(): Int +handler this.doAllocation(): Int ``` Allocate result buffers. #### bufferSize ``` -func rangeSearchResult.bufferSize(): ArchWord +handler this.bufferSize(): ArchWord ``` Get buffer size. #### getLims ``` -func rangeSearchResult.getLims(outLims: ref[ref[array[ArchWord]]]) +handler this.getLims(outLims: ref[ref[array[ArchWord]]]) ``` Get result limits array. #### getLabels ``` -func rangeSearchResult.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) +handler this.getLabels(outLabels: ref[ref[array[Int[64]]]], outDistances: ref[ref[ref[Float]]]) ``` Get labels and distances. @@ -505,21 +535,21 @@ Compute distances to vectors. [C API](https://github.com/facebookresearch/faiss/ #### setQuery ``` -func distanceComputer.setQuery(x: ref[array[Float]]): Int +handler this.setQuery(x: ref[array[Float]]): Int ``` Set query vector. #### vectorToQueryDis ``` -func distanceComputer.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int +handler this.vectorToQueryDis(i: Int[64], qd: ref[array[Float]]): Int ``` Distance to query. #### symmetricDis ``` -func distanceComputer.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int +handler this.symmetricDis(i: Int[64], j: Int[64], vd: ref[array[Float]]): Int ``` Symmetric distance. @@ -565,11 +595,9 @@ Standalone k-means. ## GPU Support - - To enable GPU acceleration, set the environment variable before running: -``` +```bash export FAISS_USE_GPU=1 ``` @@ -577,8 +605,6 @@ The library will automatically load GPU-enabled binaries when available. See [FA ## Index Factory Strings - - The `Index.new` factory method accepts strings to create different index types: * `"Flat"`: Exact search (brute force) @@ -591,8 +617,6 @@ See the [index factory documentation](https://github.com/facebookresearch/faiss/ ## Examples - - Complete working examples are in the `Examples/` directory: * **example.alusus**: Basic flat index with inner product search @@ -600,8 +624,6 @@ Complete working examples are in the `Examples/` directory: ## Performance Tips - - 1. **Index Selection**: * Use `IndexFlat` for exact search on datasets <1M vectors * Use `IndexIVF` for approximate search on larger datasets @@ -619,8 +641,6 @@ See [FAISS performance guidelines](https://github.com/facebookresearch/faiss/wik ## 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) @@ -628,9 +648,7 @@ See [FAISS performance guidelines](https://github.com/facebookresearch/faiss/wik ## License - - Copyright (c) Facebook, Inc. and its affiliates. Copyright (c) Alusus Software Ltd. for the Alusus language bindings. -This binding follows the FAISS license (MIT). See the `LICENSE` file for details. \ No newline at end of file +This binding follows the FAISS license (MIT). See the `LICENSE` file for details.