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

Escape quotes for with_bm25/with_hybrid/with_generate #422

Merged
merged 3 commits into from
Aug 17, 2023

Conversation

halilbilgin
Copy link
Contributor

This PR fixes a bug in BM25 retrieval by using json.dumps method on the query for escaping quotes.

I kept strip_newlines to maintain previous behavior on the "\n" character (instead of escaping it, strip_newlines replace it with a space).

Problem

Similar to the issue#121,
I am getting an error in with_bm25() method if query text contains double quotes, e.g.

query = 'what is an "airport"'
weaviate_client.query.get(...).with_bm25(query=query)

throws this message
...'message': 'Syntax Error GraphQL request (1:61) Expected :, found String\n...... bm25:{query: "what is an "airport""

@halilbilgin halilbilgin changed the title BUGFIX for with_bm25: use json dumps to add escape quotes BUGFIX for with_bm25: use json dumps to escape quotes Aug 16, 2023
Copy link
Contributor

@tsmith023 tsmith023 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR on this one!

Could you add another option to the parametrization of test_bm25 to demonstrate what happens when the quotes convention is reversed? I.e. "what is an 'airport'?". Cheers 😁

@weaviate-git-bot
Copy link

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Slack channel?

@dirkkul
Copy link
Collaborator

dirkkul commented Aug 17, 2023

Thanks for your contribution, for merging we need you to agree to the CLA. !

I also think that your escaping might be useful for a few hybrid and generative search. Could you check where we strip newlines in the same file and add your "dump" there, too and add tests for these? SHould be pretty straight forward :)

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 66.15% and project coverage change: -0.32% ⚠️

Comparison is base (eb3bf16) 95.43% compared to head (6d7e726) 95.11%.
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
- Coverage   95.43%   95.11%   -0.32%     
==========================================
  Files          64       64              
  Lines        8165     8129      -36     
==========================================
- Hits         7792     7732      -60     
- Misses        373      397      +24     
Files Changed Coverage Δ
test/batch/test_crud_batch.py 99.11% <ø> (-0.12%) ⬇️
weaviate/batch/crud_batch.py 90.42% <57.69%> (-4.90%) ⬇️
integration/test_batch.py 98.03% <100.00%> (ø)
integration/test_cluster.py 100.00% <100.00%> (ø)
integration/test_stress.py 87.09% <100.00%> (ø)
test/gql/test_get.py 100.00% <100.00%> (ø)
weaviate/gql/get.py 96.95% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@halilbilgin
Copy link
Contributor Author

I agree with the CLA

@halilbilgin halilbilgin changed the title BUGFIX for with_bm25: use json dumps to escape quotes Bug fixes for with_bm25/with_hybrid/with_generate: use json dumps to escape quotes Aug 17, 2023
@dirkkul dirkkul changed the title Bug fixes for with_bm25/with_hybrid/with_generate: use json dumps to escape quotes Escape quotes for with_bm25/with_hybrid/with_generate Aug 17, 2023
@dirkkul dirkkul merged commit 0fed85e into weaviate:main Aug 17, 2023
19 checks passed
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

Successfully merging this pull request may close these issues.

5 participants