Similarity Search Embedding 001
Dependencies
Connect to Weaviate
Expired Google Cloud Token
The Google Cloud's OAuth 2.0 access tokens only have a one hour lifetime. This means you have to replace the expired token with a valid one and it to Weaviate by re-instantiating the client.
Option 1: With Google Cloud CLI
Then you could run the below cell periodically.
Then run the below periodically:
Option 3: Google MakerSuite
At the time of writing (November 2023), MakerSuite is not available in all regions. See this page for the latest information.
You can obtain an API key by logging in to your MakerSuite account and creating an API key. This is the key to pass on to Weaviate. This key does not have an expiry date.
You should store your key as an env variable
palm_key = os.environ["PALM_API_KEY"] # Replace with your PALM key
client = connect_to_weaviate(palm_key)
Create a collection
Collection stores your data and vector embeddings.
Import the Data
Query Weaviate: Similarity Search (Text objects)
Similarity search options for text objects in Weaviate:
nearText Example
Find a JeopardyQuestion about "animals in movies". Limit it to only 4 responses.
Now, also request the distance for each returned item.
nearObject Example
Search through the JeopardyQuestion class to find the top 4 objects closest to id a1dd67f9-bfa7-45e1-b45e-26eb8c52e9a6. (The id was taken from the query above)
nearVector Example
Search through the JeopardyQuestion class to find the top 2 objects closest to the query vector [-0.0125526935, -0.021168863, ... ]