The Embeddinghub client can be used without a server. This is useful when using embeddings in a research environment where a database server is not necessary. If that’s the case for you, skip ahead to the next step.
Otherwise, we can use this docker command to run Embeddinghub locally and to map the container's main port to our host's port.
1
docker run featureformcom/embeddinghub -p 7462:7462
Copied!
Step 3: Initialize Python Client
If you deployed a docker container, you can initialize the python client.
1
import embeddinghub as eh
2
3
hub = eh.connect(eh.Config())
Copied!
Otherwise, you can use a LocalConfig to store and index embeddings locally.
1
hub = eh.connect(eh.LocalConfig("data/"))
Copied!
Step 4: Create a Space
Embeddings are written and retrieved from Spaces. When creating a Space we must also specify a version, otherwise a default version is used.
1
space = hub.create_space("quickstart", dims=3)
Copied!
Step 5: Upload Embeddings
We will create a dictionary of three embeddings and upload them to our new quickstart space.
1
embeddings ={
2
"apple":[1,0,0],
3
"orange":[1,1,0],
4
"potato":[0,1,0],
5
"chicken":[-1,-1,0],
6
}
7
space.multiset(embeddings)
Copied!
Step 6: Get nearest neighbors
Now we can compare apples to oranges and get the nearest neighbors.