Skip to content
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

Embedder inplace modifies input #8801

Closed
phiweger opened this issue Feb 3, 2025 · 1 comment
Closed

Embedder inplace modifies input #8801

phiweger opened this issue Feb 3, 2025 · 1 comment

Comments

@phiweger
Copy link

phiweger commented Feb 3, 2025

Hi,

I take this example from the OpenAIDocumentEmbedder docstring:

from haystack import Document
from haystack.components.embedders import OpenAIDocumentEmbedder

doc = Document(content="I love pizza!")
# doc.embedding is None, as I would expect

document_embedder = OpenAIDocumentEmbedder()

result = document_embedder.run([doc])
print(result['documents'][0].embedding)
# Surprising to me, doc.embedding now also holds a vector.

^ Is this intended behaviour?

Maybe it could be made more explicit like in pytorch where inplace methods carry a trailing underscore: document_embedder.run_([doc]) OR a copy.deepcopy could be added somewhere?

@lbux
Copy link
Contributor

lbux commented Feb 4, 2025

This seems to be working as intended #6107

@phiweger phiweger closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants