orcalib.index_handle#
IndexHandle
#
A handle to an index in an Orca database.
Usually this is not called directly but through the db.get_index
or db.create_vector_index
etc. methods on a database handle.
Parameters:
-
name
(str
) –Name of this index
-
db_name
(str
) –Database that this index belongs to
-
table_name
(str
) –Table that this index belongs to
-
column_name
(ColumnName
) –Name of the column that this index is built on
-
column_type
(OrcaTypeHandle
) –Type of the column that this index is built on
-
embedding_type
(OrcaTypeHandle
) –Type of the vector embedding used by this index (if any)
-
index_type
(str
) –Type of this index
-
artifact_columns
(dict[ColumnName, str | OrcaTypeHandle]
) –Artifact columns that are available from the index
embedding_dim
property
#
Get the embedding dimension of this index (if any).
Returns:
-
int
–Embedding dimension if this index has an embedding,
None
otherwise
Raises:
-
NotImplementedError
–If the embedding type is not a numeric type
Examples:
scan
#
Entry point for a search query on the index
Parameters:
-
query
(Any
) –Query value for the index, must match the column type this index is defined on, for example this would be a string if this is a text index
-
drop_exact_match
(bool
, default:False
) –If True, drop exact matches from the results
-
exact_match_threshold
(float
, default:EXACT_MATCH_THRESHOLD
) –Threshold for exact match, if the similarity score is above this
Returns:
-
DefaultIndexQuery
–chainable query builder object, see example
Examples:
vector_scan
#
Entry point for a vector search query on the index that returns a results batch
Parameters:
-
query
(Any
) –A batch of queries to scan the index with, can either be a list of vectors represented by a list of floats each, or a list of for example strings if this is a text index. Can also be a single value, which will be treated as a list of one.
-
drop_exact_match
(bool
, default:False
) –If True, drop exact matches from the results
-
exact_match_threshold
(float
, default:EXACT_MATCH_THRESHOLD
) –Threshold for exact match, if the similarity score is above this
Returns:
-
VectorIndexQuery
–chainable query handle object, see example
Examples:
>>> res = (
... index.vector_scan(torch.rand(2, index.embedding_dim).tolist())
... .select("$embedding", "label")
... .fetch(10)
... )
>>> res.to_tensor("$embedding").shape, res.to_tensor("$embedding").dtype
torch.Size([2, 10, 768]), torch.float64
>>> res.to_tensor("label").shape, res.to_tensor("label").dtype
torch.Size([2, 10]), torch.int64
get_status
#
embed
#
Encode text into vectors using the index’s embedding model.
Parameters:
-
text
(str | list[str]
) –Text to encode. Can be a single string or a list of strings.
-
result_format
(Literal['pt', 'list']
, default:'pt'
) –Format of the result. Can be “pt” for a PyTorch tensor or “list” for a list of lists.
Returns:
Examples: