Find answers from the community

Updated 9 months ago

Hi guys, i have a question regarding the

Hi guys, i have a question regarding the input array/tensor size in LlamaIndex with vectorstore index/storage context where i'm getting the following
Plain Text
ValueError: shapes (0,512) and (384,) not aligned: 512 (dim 1) != 384 (dim 0)

with the following code

Plain Text
# We will be using local storage instead of a host qdrant server
client = qdrant_client.QdrantClient(path="./sfa_test",)
client.create_collection(collection_name="SFA",vectors_config=models.VectorParams(size=512,distance=models.Distance.COSINE))

vector_store = QdrantVectorStore(client=client,collection_name="SFA")
storage_context = StorageContext.from_defaults(vector_store=vector_store,)

from llama_index.core import ServiceContext,Document
docs = SimpleDirectoryReader("./data/").load_data()
# docs = docs [150:160]
docs = [Document(text="Hello world"), Document(text="Hello there")]
Settings.embed_model = resolve_embed_model("local:BAAI/bge-small-en-v1.5")
Settings.llm = Ollama(model="mistral")
embed = resolve_embed_model("local:BAAI/bge-small-en-v1.5")
llm = Ollama(model="mistral")

SERVICE_CONTEXT = ServiceContext.from_defaults(embed_model=embed,llm=llm)

pipeline = IngestionPipeline(
    transformations=[
        KeywordExtractor(llm=llm),
        TokenTextSplitter(chunk_size=512,chunk_overlap=256)
    ],
    vector_store=vector_store
)
nodes = pipeline.run(documents=docs,num_workers=16,)

index = VectorStoreIndex.from_vector_store(vector_store=vector_store,embed_model=embed)

query_engine = index.as_query_engine(llm=llm)
response = query_engine.query("Give me a random example")
print(response)


I've tested that the 512 in (0,512) seems to be from the size of models.VectorParams in the line

Plain Text
client.create_collection(collection_name="SFA",vectors_config=models.VectorParams(size=512,distance=models.Distance.COSINE))

but where is the 384 in (382,) coming from?
B
2 comments
I get a similar error ValueError: could not broadcast input array from shape (384,) into shape (512,) when doing the following
Plain Text
index = VectorStoreIndex.from_documents(documents=docs,storage_context=storage_context,)


But i do not get any errors when using the following

Plain Text
index = VectorStoreIndex.from_documents(documents=docs)

so the error should be from the QDrant vector store/ VectorStoreIndex that i am creating? What should i do to fix the error?

Thanks!
Edit: SOLVED, but i'll jsut leave this here just in case if comes in useful for others The problem was with the embedding dimension/size of the embedding model and the VectorParam in the qDrant vectorstore. The dimension of bge-small-en-v1.5 is 384, which causes issues as it is not a multiple of 512 and hence causes trouble. Changing the dimensions so that the VectorParam size matches that of the embedding model used solves the issue
Add a reply
Sign up and join the conversation on Discord