Skip to main content

AlayaDB

Project description

QUICK START

  1. Install Packge

pip install AlayaDB
  1. Import Dataset

from AlayaDataset import *
data = VECS(base_fname='/data/cohere-768-euclidean/cohere-768-euclidean_base.fvecs',
            query_fname='/data/cohere-768-euclidean/cohere-768-euclidean_query.fvecs',
            gt_fname='/data/cohere-768-euclidean/cohere-768-euclidean_gti.ivecs',
            metric='L2')

 data = HDF5(file_path='/data/cohere-768-euclidean.hdf5',
             metric='L2')

data = NPARRAY(database=database, query=query, gt=gt, metric='L2')
  1. Create Alaya Instance

from AlayaDB import Alaya
alaya = Alaya(data.database,        # dataset
            index_type=Alaya.HNSW   # index type
            )
  1. search

# normal search
alaya.search(query=data.query)

# search with trace
alaya.search(query=data.query, is_trace=True, save_json_dir='data/jsons')

API

alayapy.Alaya

STATIC VARIABLES

# graph type
MERGRAPH = "MERGRAPH"
HNSW = "HNSW"
NSG = "NSG"

# Methods for distance calculation
L2 = "L2"   # Euclidean distance
IP = "IP"   # Angle calculation
EUCLIDEAN = "L2"
ANGULAR = "IP"

Alaya.HNSW

__init__

def __init__(self,
            database: np.array,
            index_type: str=MERGRAPH,
            metric: str=L2,
            M: int=32,
            L: int=300,
            level: int=3,
            optimizer: int=os.cpu_count(),
            num_threads: int=os.cpu_count(),
            index_cache_dir: str="data/alaya_index",
            is_cache_index: bool=True,
            is_rebuild: bool=False
            ):

  """
  Args:
    database(np.array): 数据集, shape(n, dim)
    index_type(str): 索引类型, default=MERGRAPH
    metric(str): 距离度量, default=L2
    M(int): MERGRAPH的M参数, default=32
    L(int): MERGRAPH的L参数, default=300
    level(int): MERGRAPH的level参数, default=3
    optimizer(int): 调用优化器的线程数, default=os.cpu_count()
    num_threads(int): search时使用的线程数, default=os.cpu_count()
    index_cache_dir(str): 索引缓存目录, default="data/alaya_index"
    is_cache_index(bool): 是否缓存索引, default=True
    is_rebuild(bool): 是否重新构建索引, default=False

  Returns:
    None
  """
  1. call alaya = Alaya(dataset=dataset, index_type=index_type) will create graph and save in ./data/index_index/

  2. The name of the saved graph created isf'Alaya-{self.index_type}-{self.metric}-{self.M}-{self.__gene_md5()}', e.g. Alaya-HNSW-L2-32-55ee368c93392e849c40de551b62fdb2

  3. If you want to change the saved path, use index_cache_dir='/you/save/path'

  4. If you don’t want to save the graph, use is_cache_index=False

  5. If the graph is rebuilt regardless of whether it is cached or not, useis_rebuild=True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

AlayaDB-1.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file AlayaDB-1.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for AlayaDB-1.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd7eb1e61cec0f4616f99e5cdd91a5511915244e890bf8c5803c510f2be5ef9e
MD5 60edd84655cd37f5ba6484515398a078
BLAKE2b-256 4e430f876e67c43b933afc55d59ce86ed31a993ea1d7398c6bd5e76d1973b6d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page