Index
Object Hierarchy:
Description:
public class Index : Object
FAISS index wrapper for vector storage and similarity search.
Provides thread-safe access to FAISS operations (FAISS itself is not thread-safe, so all operations are protected by a mutex). Supports
both creating new indexes and loading existing ones from disk.
The index uses HNSW (Hierarchical Navigable Small World) algorithm for efficient approximate nearest neighbor search. New indexes are
created with M=16 for a good balance of speed, recall, and memory usage.
Usage Example
// Create or load index
var index = new OLLMvector.Index("/path/to/index.faiss", 1024);
// Add vectors
var vectors = new OLLMvector.FloatArray(1024);
vectors.add(vector1);
vectors.add(vector2);
index.add_vectors(vectors);
// Search for similar vectors
var results = index.search(query_vector, k: 10);
// Save index to disk
index.save_to_file("/path/to/index.faiss");
Content:
Properties:
Creation methods:
- public Index (string filename, int dim) throws Error
Constructor.
Methods:
- public void add_vectors (FloatArray vectors) throws Error
Adds vectors in batch to the FAISS index.
- public uint64 get_total_vectors ()
Gets the total number of vectors in the index.
- public float[] reconstruct_vector (int64 vector_id) throws Error
Reconstruct a vector by its ID.
- public void save_to_file (string filename) throws Error
Saves the FAISS index to a file.
- public SearchResult[] search (float[] query_vector, uint64 k = 5, IDSelector? selector = null) throws Error
Search for similar vectors.
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref