Find answers from the community

Updated 10 months ago

Is there someway by which I can use

At a glance

The community member is asking if there is a way to use Euclidean distance for similarity rather than cosine similarity when using the LlamaIndex library. In the comments, another community member suggests that the choice of distance metric depends on the embeddings model being used, and provides an example of using Euclidean distance with the Pinecone vector store. Another community member adds that if using a local embeddings model, the embedding class can be subclassed to change the similarity mode.

Useful resources
Is there someway by which I can use euclidean distance for similarity rather than cosine for retrieval using llamaindex?
T
W
2 comments
Which embeddings model are you using? OpenAI for example recommends using cosine similarity: https://help.openai.com/en/articles/8984345-which-distance-function-should-i-use

But there are ways to use euclidean if you want to, for example with Pinecone:

Plain Text
if "quickstart-index" not in indexes:
    # dimensions are for text-embedding-ada-002
    pinecone.create_index(
        "quickstart-index", dimension=1536, metric="euclidean", pod_type="p1"
    )

https://docs.llamaindex.ai/en/stable/examples/vector_stores/existing_data/pinecone_existing_data/?h=pinecone
Add a reply
Sign up and join the conversation on Discord