needlestack.indices package¶
Submodules¶
needlestack.indices.faiss_indices module¶
needlestack.indices.index module¶
-
class
needlestack.indices.index.BaseIndex[source]¶ Bases:
objectBase class for index implementations. Defines interfaces for populating data and performing kNN queries.
-
property
count¶ Number of vectors in the vector space
- Return type
int
-
property
dimension¶ Spatial dimensions for the vector space
- Return type
int
-
static
from_proto(proto)[source]¶ Factory method to construct the correct implementation of a BaseIndex from a protobuf. Specific index types are imported in this function so their dependent packages do not need to be installed
-
get_vector_and_metadata(id)[source]¶ Returns the vector and metadata for a particular item id
- Parameters
id (
str) – ID within metadata- Return type
Tuple[ndarray,Metadata]
-
knn_search(X, k)[source]¶ Returns an array of distances and index ids
- Parameters
X (
ndarray) – Matrix of vectors to perform kNN searchk (
int) – Number of neighbors
- Return type
Tuple[ndarray,ndarray]
-
modified_time= None¶
-
populate(data)[source]¶ Populate BaseIndex from dictionary
- Parameters
data (
Dict[~KT, ~VT]) – Dictionary of key, value pairs for attributes
-
populate_from_proto(proto)[source]¶ Populate BaseIndex from protobuf defining data source
- Parameters
proto – Protobuf with data on how to populate a particular BaseIndex implementation
-
query(X, k)[source]¶ Returns a list of list of knn query results. Each result is a tuple of (distance, metadata) pairs.
- Parameters
X (
ndarray) – Matrix of vectors to perform kNN search fork (
int) – Number of neighbors
- Return type
List[List[SearchResultItem]]
-
property