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

ValueError: Expected where to have exactly one operator, got {} in query. #2039

Open
gmdorf opened this issue Nov 21, 2024 · 2 comments
Open

Comments

@gmdorf
Copy link

gmdorf commented Nov 21, 2024

🐛 Describe the bug

This example from the docs: https://docs.embedchain.ai/api-reference/app/search,

from embedchain import App

app = App()
app.add("https://www.forbes.com/profile/elon-musk")

context = app.search("What is the net worth of Elon?", num_documents=2)
print(context)

when used verbatim, raises this exception:

Traceback (most recent call last):
  File "/home/gavid/crawler_test/test1.py", line 9, in <module>
    context = app.search("What is the net worth of Elon?", num_documents=2)
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/embedchain/embedchain.py", line 712, in search
    return [{"context": c[0], "metadata": c[1]} for c in self.db.query(**params)]
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/embedchain/vectordb/chroma.py", line 221, in query
    result = self.collection.query(
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/chromadb/api/models/Collection.py", line 210, in query
    query_request = self._validate_and_prepare_query_request(
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/chromadb/api/models/CollectionCommon.py", line 93, in wrapper
    raise type(e)(msg).with_traceback(e.__traceback__)
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/chromadb/api/models/CollectionCommon.py", line 90, in wrapper
    return func(self, *args, **kwargs)
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/chromadb/api/models/CollectionCommon.py", line 294, in _validate_and_prepare_query_request
    validate_filter_set(filter_set=filters)
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/chromadb/api/types.py", line 339, in validate_filter_set
    validate_where(filter_set["where"])
  File "/home/gavid/.asdf/installs/python/3.10.15/lib/python3.10/site-packages/chromadb/api/types.py", line 598, in validate_where
    raise ValueError(f"Expected where to have exactly one operator, got {where}")
ValueError: Expected where to have exactly one operator, got {} in query.

My python version: 3.10.15
My embedchain version: 0.1.125

@Cirr0e
Copy link

Cirr0e commented Nov 21, 2024

Hi there! I've taken a look at the issue you're experiencing with the Embedchain search method.

The error ValueError: Expected where to have exactly one operator, got {} in query suggests there might be an issue with how the search method is being called or how the database is configured.

Here are a few things to try:

  1. Explicit Initialization:
from embedchain import App
from chromadb.config import Settings

# Try specifying explicit Chroma settings
app = App(config={
    "collection_name": "my_collection",
    "persist_directory": "./chroma_db"
})
  1. Modify Search Method:
# Try specifying explicit search parameters
context = app.search("What is the net worth of Elon?", 
                     num_documents=2, 
                     where={})  # Explicitly pass an empty dict
  1. Check Database State:
    Make sure you've actually added documents to the database before searching. The example you provided adds a single URL, but ensure it's been processed:
app = App()
app.add("https://www.forbes.com/profile/elon-musk")
app.query()  # Ensure database is populated

context = app.search("What is the net worth of Elon?", num_documents=2)

A few additional troubleshooting steps:

  • Verify you're using the latest version of Embedchain
  • Check that Chroma is properly installed
  • Ensure you have the necessary dependencies

Could you confirm:

  1. Have you successfully added documents to the database before searching?
  2. What version of Chroma and Embedchain are you using?
  3. Can you share the full traceback and your complete initialization code?

Let me know if any of these suggestions help or if you need more detailed guidance!

@gmdorf
Copy link
Author

gmdorf commented Nov 21, 2024

My issue is caused by a slight typo in the source code. PR here: #2042

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