Indexes are used to speed up queries by allowing fast – O(log n) – lookup of documents that have specific values or ranges of values.
More...
Indexes are used to speed up queries by allowing fast – O(log n) – lookup of documents that have specific values or ranges of values.
The values may be properties, or expressions based on properties.
An index will speed up queries that use the expression it indexes, but it takes up space in the database file, and it slows down document saves slightly because it needs to be kept up to date when documents change.
Tuning a database with indexes can be a tricky task. Fortunately, a lot has been written about it in the relational-database (SQL) realm, and much of that advice holds for Couchbase Lite. You may find SQLite's documentation particularly helpful since Couchbase Lite's querying is based on SQLite.
Supported index types: Value indexes speed up queries by making it possible to look up property (or expression) values without scanning every document. They're just like regular indexes in SQL or N1QL. Multiple expressions are supported; the first is the primary key, second is secondary. Expressions must evaluate to scalar types (boolean, number, string).
Full-Text Search (FTS) indexes enable fast search of natural-language words or phrases by using the MATCH()
function in a query. A FTS index is required for full-text search: a query with a MATCH()
function will fail to compile unless there is already a FTS index for the property/expression being matched.
(Enterprise Edition Only) Vector indexes allows efficient search of ML vectors by using the VECTOR_MATCH()
function in a query. The CouchbaseLiteVectorSearch
extension library is required to use the functionality. Use CBL_EnableVectorSearch function to set the directoary path containing the extension library.
◆ CBLIndexUpdater
◆ CBLQueryIndex
◆ CBLVectorEncoding
◆ CBLDistanceMetric
Distance metric to use in CBLVectorIndexConfiguration.
Enumerator |
---|
kCBLDistanceMetricEuclideanSquared | Squared Euclidean distance (AKA Squared L2)
|
kCBLDistanceMetricCosine | Cosine distance (1.0 - Cosine Similarity)
|
kCBLDistanceMetricEuclidean | Euclidean distance (AKA L2)
|
kCBLDistanceMetricDot | Dot-product distance (Negative of dot-product)
|
◆ CBLScalarQuantizerType
Scalar Quantizer encoding type.
Enumerator |
---|
kCBLSQ4 | 4 bits per dimension
|
kCBLSQ6 | 6 bits per dimension
|
kCBLSQ8 | 8 bits per dimension
|
◆ CBLIndexUpdater_Count()
ENTERPRISE EDITION ONLY.
Returns the total number of vectors to compute and set for updating the index.
- Parameters
-
updater | The index updater. |
- Returns
- The total number of vectors to compute and set for updating the index.
◆ CBLIndexUpdater_Finish()
ENTERPRISE EDITION ONLY.
Updates the index with the computed vectors and removes any index rows for which null vector was given. If there are any indexes that do not have their vector value set or are skipped, a error will be returned.
- Note
- Before calling
CBLIndexUpdater_Finish
, the set vectors are kept in the memory.
- Warning
- The index updater cannot be used after calling
CBLIndexUpdater_Finish
.
- Parameters
-
updater | The index updater. |
outError | On failure, an error is written here. |
- Returns
- True if success, or False if an error occurred.
◆ CBLIndexUpdater_Release()
◆ CBLIndexUpdater_Retain()
◆ CBLIndexUpdater_SetVector()
ENTERPRISE EDITION ONLY.
Sets the vector for the value corresponding to the given index. Setting null vector means that there is no vector for the value, and any existing vector will be removed when the CBLIndexUpdater_Finish
is called.
- Parameters
-
updater | The index updater. |
index | The zero-based index. |
vector | A pointer to the vector which is an array of floats, or NULL if there is no vector. |
dimension | The dimension of vector . Must be equal to the dimension value set in the vector index config. |
outError | On failure, an error is written here. |
- Returns
- True if success, or False if an error occurred.
◆ CBLIndexUpdater_SkipVector()
void CBLIndexUpdater_SkipVector |
( |
CBLIndexUpdater * |
updater, |
|
|
size_t |
index |
|
) |
| |
ENTERPRISE EDITION ONLY.
Skip setting the vector for the value corresponding to the index. The vector will be required to compute and set again when the CBLQueryIndex_BeginUpdate
is later called.
- Parameters
-
updater | The index updater. |
index | The zero-based index. |
◆ CBLIndexUpdater_Value()
ENTERPRISE EDITION ONLY.
Returns the valut at the given index to compute a vector from.
- Note
- The returned Fleece value is valid unilt its CBLIndexUpdater is released. If you want to keep it longer, retain it with
FLRetain
.
- Parameters
-
updater | The index updater. |
index | The zero-based index. |
- Returns
- A Fleece value of the index's evaluated expression at the given index.
◆ CBLQueryIndex_BeginUpdate()
ENTERPRISE EDITION ONLY.
Finds new or updated documents for which vectors need to be (re)computed and returns an CBLIndexUpdater object for setting the computed vectors to update the index. If the index is not lazy, an error will be returned.
- Note
- For updating lazy vector indexes only.
-
You are responsible for releasing the returned A CBLIndexUpdater object.
- Parameters
-
index | The index. |
limit | The maximum number of vectors to be computed. |
outError | On failure, an error is written here. |
- Returns
- A CBLIndexUpdater object for setting the computed vectors to update the index, or NULL if the index is up-to-date or an error occurred.
◆ CBLQueryIndex_Collection()
Returns the collection that the index belongs to.
- Parameters
-
- Returns
- A CBLCollection instance that the index belongs to.
◆ CBLQueryIndex_Name()
Returns the index's name.
- Parameters
-
- Returns
- The name of the index.
◆ CBLQueryIndex_Release()
◆ CBLQueryIndex_Retain()
◆ CBLVectorEncoding_CreateNone()
◆ CBLVectorEncoding_CreateProductQuantizer()
Creates a Product Quantizer encoding to use in CBLVectorIndexConfiguration.
- Parameters
-
subquantizers | Number of subquantizers. Must be > 1 and a factor of vector dimensions. |
bits | Number of bits. Must be >= 4 and <= 12. |
- Returns
- A Product Quantizer encoding object.
◆ CBLVectorEncoding_CreateScalarQuantizer()
Creates a Scalar Quantizer encoding to use in CBLVectorIndexConfiguration.
- Parameters
-
type | Scalar Quantizer Type. |
- Returns
- A Scalar Quantizer encoding object.
◆ CBLVectorEncoding_Free()
Frees a CBLVectorEncoding object.
The encoding object can be freed after the index is created.