Replies: 3 comments
-
🤖 Yes, LlamaIndex can indeed be used to create an embedding of a user's question and compare it against a collection of embeddings in the vectorbase. The Once the embedding of a user's question is generated, it can be compared against a collection of embeddings in the vectorbase using the Here is a sample code snippet for the def similarity(
self,
embedding1: Embedding,
embedding2: Embedding,
mode: SimilarityMode = SimilarityMode.DEFAULT,
) -> float:
"""Get embedding similarity."""
return similarity(embedding1=embedding1, embedding2=embedding2, mode=mode) And the def similarity(
embedding1: Embedding,
embedding2: Embedding,
mode: SimilarityMode = SimilarityMode.DEFAULT,
) -> float:
"""Get embedding similarity."""
if mode == SimilarityMode.EUCLIDEAN:
# Using -euclidean distance as similarity to achieve same ranking order
return -float(np.linalg.norm(np.array(embedding1) - np.array(embedding2)))
elif mode == SimilarityMode.DOT_PRODUCT:
product = np.dot(embedding1, embedding2)
return product
else:
product = np.dot(embedding1, embedding2)
norm = np.linalg.norm(embedding1) * np.linalg.norm(embedding2)
return product / norm This function calculates the similarity between two embeddings based on the selected mode. You can find more details in the source code of LlamaIndex, specifically in the llama_index/embeddings/elasticsearch.py and llama_index/embeddings/base.py files. Please note that the I hope this answers your question. If you have any further queries, feel free to ask. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
so after i get the simmilar embedding vector from the vetctorbase, how to send to LLM for inquiry |
Beta Was this translation helpful? Give feedback.
-
llama-index already solves it behind the hood on query time, so you don't have to worry about it |
Beta Was this translation helpful? Give feedback.
-
Question Validation
Question
A user will ask a question,
create an embedding of the question,
and compare it against the collection of embeddings in the vectorbase
may i know if llama_index can do this?
Beta Was this translation helpful? Give feedback.
All reactions