-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add_texts method of Weaviate vector store creats wrong embeddings #4933
fix: add_texts method of Weaviate vector store creats wrong embeddings #4933
Conversation
…es wrong embeddings
if "uuids" in kwargs: | ||
_id = kwargs["uuids"][i] | ||
else: | ||
_id = get_valid_uuid(uuid4()) | ||
|
||
if self._embedding is not None: | ||
embeddings = self._embedding.embed_documents(list(doc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch! i wonder if we should just change list(doc) -> [doc] and leave the rest the same. reason being current implementation lets us lazily load in texts, whereas calling list(texts) up front would load all of them into memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch! i wonder if we should just change list(doc) -> [doc] and leave the rest the same. reason being current implementation lets us lazily load in texts, whereas calling list(texts) up front would load all of them into memory
I checked the add_texts
methods of all vectore stores. Here is what I found:
- Twelve vector stores turn the potential iterable
texts
into a list first and then embed them:
- chroma
- pgvector
- qdrant
- supabase
- analyticdb
- atlas
- deeplake
- elastic_vector_search
- lancedb
- milvus
- opensearch_vector_search
- tair
- Four vector stores that iterate over
texts
and embed text one by one lazily:
- faiss
- redis
- pinecone
- myscale
The behavious are not consistent. But most vector stores simply turn the texts
variable into a list first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea we definitely haven't been consistent about it, which is on us. and it's possible for a lot of workloads / embedding methods that embedding all the texts at once is more efficient. but think i'd prefer to not change behavior in an existing vector store until we've come up with a best practice that we apply everywhere. meaning in this case slight preference to keep lazy for now (otherwise somebody who's using Weaviate today could see their memory usage change next update for seemingly no reason)
fix a bug in the add_texts method of Weaviate vector store that creats wrong embeddings
The following is the original code in the
add_texts
method of the Weaviate vector store, from line 131 to 153, which contains a bug. The code here includes some extra explanations in the form of comments and some omissions.To fix this bug, I pulled the embedding operation out of the for loop and embed all texts at once.
According to the contributing.md doc, it seems I can have my twitter account mentioned? I'd love that very much. My twitter handler is
ShawnDeveloping
. HAHA.Who can review?
Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:
@dev2049