# Ensure that Python 3.11 or 3.12 is installed# Or create a virtual environment with Python 3.11 or 3.12:conda create -n cyborg-env python=3.12# Activate the virtual environment:conda activate cyborg-env# Install Cyborg Vector Search:pip install cyborg_vector_search_py -i https://dl.cloudsmith.io/<token>/cyborg/cyborg-vector-search/python/simple/
You will need to replace <token> with your token provided by Cyborg.
2
Create a Client
Create a Cyborg Vector Search client:
Copy
Ask AI
import cyborg_vector_search_py as cvsimport secrets# Using `memory` storage for this example# `redis` and `postgres` are also supportedindex_location = cvs.DBConfig("memory") # Where encrypted index is stored (for queries)config_location = cvs.DBConfig("memory") # Where encrypted index config is stored (for config/loading)items_location = cvs.DBConfig("memory") # Where item contents are stored (for upsert/get)# Create a clientclient = cvs.Client(index_location, config_location, items_location)
Create an encrypted index with Cyborg Vector Search:
Copy
Ask AI
# ... Continuing from the previous step# Create an IVFFlat index config (can also be IVF/IVFPQ)# Using an example vector dimension of 128, and number of lists of 1024index_config = cvs.IndexIVFFlat(dimension=128, n_lists=1024)# Generate an encryption key for the indexindex_key = secrets.token_bytes(32)# Create an encrypted indexindex = client.create_index("my_index", index_key, index_config)
# ... Continuing from the previous step# Query the encrypted indexquery_vector = [0.1, 0.2, 0.3, 0.4]results = index.query(query_vector)# Print the resultsfor result in results: print(f"ID: {result.id}, Distance: {result.distance}")
# ... Continuing from the previous step# Retrieve items from the encrypted indexids = [1, 2, 3]items = index.get_items(ids)# Print the itemsfor i in range(len(ids)): print(f"ID: {ids[i]}, Contents: {items[i]}")