Find answers from the community

Updated 4 months ago

Hi, I use the following code to get the

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