Find answers from the community

Updated 6 months ago

Hi, I use the following code to get the

At a glance

The community member is using the llama_index library to retrieve the two most relevant nodes and their metadata information. However, they are unable to get the embedding vector of the relevant nodes. A comment from another community member indicates that the chroma class does not return embeddings, which explains the error the original poster is encountering when trying to get the embedding vector. There is no explicitly marked answer in the comments.

Useful resources
Hi, I use the following code to get the two most relevant nodes. I can also get the metadata information. But how do I get the embedding vector of relevant nodes?
Plain Text
import chromadb
from llama_index.core.storage.storage_context import StorageContext
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.embeddings.huggingface import HuggingFaceEmbedding 
from llama_index.core import (
    Document,
    VectorStoreIndex,
    Settings
)

documents = Document(
    text=text,
    metadata={
        'filename': file_name,
        'keyword': keyword,
    }
)

...

vector_store = ChromaVectorStore(chroma_collection=collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
Settings.embed_model = HuggingFaceEmbedding(model_name='BAAI/bge-large-zh-v1.5')

index = VectorStoreIndex.from_documents(
    documents,
    storage_context=storage_context,
    Settings=Settings
)

...

retriever = index.as_retriever(similarity_top_k=3)
relevant_nodes = retriever.retrieve("my query")


I try to get vector:
Plain Text
relevant_nodes[0].get_embedding()

# Output
raise ValueError("embedding not set.")
ValueError: embedding not set.
Add a reply
Sign up and join the conversation on Discord