Comments (9)
To address the ValueError
related to embedding dimensions not aligning (512 or 1024 vs. 384), ensure you're setting the max_length
parameter correctly when initializing the HuggingFaceEmbedding
object. This parameter should match the dimensionality of the embeddings you intend to use. Here's how you can adjust it:
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
embed_model = HuggingFaceEmbedding(
model_name="/home/techplus-820/w/bge-large-en-v1.5", # Adjust the model_name as needed
max_length=1024 # Set this to 512 or 1024 based on your model's embedding dimensions
)
Settings.embed_model = embed_model
This adjustment ensures the embedding model is configured to handle the input dimensions you're working with, thus avoiding the dimension mismatch error.
If the issue persists, it might be due to a mismatch between the dimensions of the vectors in your query and those in your vector store. Ensure the embedding_dimension
parameter of your vector store matches the dimension of your query vectors to resolve this.
Details
Sources
- [Question]: Neo4jVectorStore with custom Embedding Model
- Dimensionality of query embeddings does not match index dimensionality
- [Bug]: PGVECTOR sqlalchemy.exc.StatementError: (builtins.ValueError) expected 1536 dimensions, not 4096
- llama-index-integrations/embeddings/llama-index-embeddings-huggingface/llama_index/embeddings/huggingface/base.py
About Dosu
This 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.
To continue the conversation, mention @dosu.
from llama_index.
@logan-markewich Thank you very much! The quick fixing solution is that I should delete the old ./storage directory after changing the embedding model. It now works perfectly as expected.Thank you very much again for helping me get out of the rabbit hole!
from llama_index.
Hello @hushuitian! 👋 I'm Dosu, a bot here to assist you with bug fixes, answer your questions, and guide you on contributing while we wait for a human maintainer. I'm taking a look at your issue and will provide a full answer shortly.
from llama_index.
@hushuitian you need to make sure you are querying with the same embedding model that created the index.
If you switch embedding models, you need to build a new index
from llama_index.
@Disiok Thanks for fixing advice! But it doesn't work.
from llama_index.
@hushuitian you need to make sure you are querying with the same embedding model that created the index.
If you switch embedding models, you need to build a new index
Thanks a lot for your advice! In my test case. It uses SimpleVectorStore. In get_top_k_embeddings() of ~/.local/lib/python3.10/site-packages/llama_index/core/indices/query/embedding_utils.py,
...
embeddings_np = np.array(embeddings)
...
embeddings_np.shape is set to (22, 384). Where is the number 384 coming from? Some default configurations somewhere? How can we change this shape to (22,512) that will correctly match query_embedding_np.shape (512,)?
from llama_index.
@hushuitian there is a mismatch between the embeddings used to create the index, and the embeddings used to query the index. That is where the 384 and 512 are coming from
from llama_index.
You can't change the embedding model and query an existing index, which is what you are doing
If you change the embedding model, you NEED to create the index again using VectorStoreIndex.from_documents(documents, ...)
or VectorStoreIndex(nodes, ...)
before you can query again
from llama_index.
In the notebook you are following, there is this block of code
import os
from llama_index.core import (
StorageContext,
VectorStoreIndex,
load_index_from_storage,
)
if not os.path.exists("storage"):
index = VectorStoreIndex.from_documents(docs)
# save index to disk
index.set_index_id("vector_index")
index.storage_context.persist("./storage")
else:
# rebuild storage context
storage_context = StorageContext.from_defaults(persist_dir="storage")
# load index
index = load_index_from_storage(storage_context, index_id="vector_index")
If you change the embedding model, you should delete the existing storage folder so that the index is created again
from llama_index.
Related Issues (20)
- [Bug]: System prompt has no effect using Ollama HOT 3
- API key for content summarization HOT 1
- [Question]: How to write production grade code HOT 3
- [Question]: Generate Only SQL Query HOT 3
- [Question]: how does llamaindex support large datasets? HOT 11
- [Bug]: MongoDBAtlasVectorSearch & VectorStoreIndex.from_vector_store are not working as expected HOT 5
- [Bug]: LanceDBVectorStore database size blows up on creation HOT 1
- [Question]: node structure for elasticsearch ~ Dosubot
- [Question]: SQL query response has 'sql\n' from SQLAutoVectorQueryEngine HOT 1
- [Question]: I want to get the coordinates using Unstructured as the metadata of nodes HOT 1
- [Bug]: async functions do not work.. HOT 6
- [Feature Request]: HOT 1
- [Bug]: ChatSummaryMemoryBuffer failed with chat_engine HOT 1
- [Bug]: When using HyDE, Langfuse doesn't log trace event HOT 4
- [Bug]: VertexAIVectorStore fails w/ IndexError HOT 1
- [Bug]: HOT 1
- Enable Gpu when Generating Sparse vectors with Qdrant hybrid Mode. HOT 1
- [Question]: Is data shared when creating embeddings or querying? HOT 2
- [Question]: Is it expected that `VectorStoreIndex.persist` and `load_index_from_storage` are not symmetric? HOT 2
- [Bug]: Cannot use SentenceWindowNodeParser with custom SentenceSplitter HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llama_index.