Deep Lake Vector Store API

Running Vector Search in the Deep Lake Vector Store module.

Search Options for Deep Lake Vector Stores in the Deep Lake API

This tutorial requires installation of:

!pip3 install "deeplake[enterprise]" langchain openai tiktoken

Vector Search Using Python Logic

Let's load the same vector store used in the Quickstart and run embeddings search based on a user prompt using the Deep Lake Vector Store module.

from deeplake.core.vectorstore.deeplake_vectorstore import DeepLakeVectorStore
import openai
import os

os.environ['OPENAI_API_KEY'] = <OPENAI_API_KEY>

vector_store_path = 'hub://activeloop/paul_graham_essay'

vector_store = DeepLakeVectorStore(
    path = vector_store_path,
    read_only = True
)

Next, let's define an embedding function using OpenAI. It must work for a single string and a list of strings, so that it can both be used to embed a prompt and a batch of texts.

Lets run a simple vector search using default options, which performs simple cosine similarity search in Python on the client.

The search_results is a dictionary with keys for the text, score, id, and metadata, with data ordered by score. By default, it returns 4 samples ordered by similarity score, and if we examine the first returned text, it appears to contain the text about trust and safety models that is relevant to the prompt.

Returns:

Vector search can be combined with other search logic for performing more advanced queries. Let's define a function compatible with deeplake.filter for filtering data prior to the vector search. The function below will filter samples that contain the word "program" in the text tensor.

Let's run the vector search with the filter above, return more samples (k = 10), and perform similarity search using L2 metric (distance_metric = "l2"):

We can verity that the word "program" is present in all of the results:

Vector Search Using Compute Engine

Deep Lake offers advanced search features using Compute Engine, which executes queries with higher performance in C++, and offers querying using Deep Lake's Tensor Query Language (TQL).

Let's load a larger Vector Store for running more interesting queries:

Simple Vector Search

Lets run a simple vector search and specify exec_option = "compute_engine", which will performs cosine similarity search using Compute Engine on the client.

If we examine the first returned text, it appears to contain the text about trust and safety models that is relevant to the prompt.

Returns:

Vector Search Using Managed Tensor Database

Tutorial Coming Soon

Last updated

Was this helpful?