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

Updated cohere notebook for video #317

Merged
merged 6 commits into from
Aug 29, 2024
Merged

Updated cohere notebook for video #317

merged 6 commits into from
Aug 29, 2024

Conversation

maxhniebergall
Copy link
Member

@maxhniebergall maxhniebergall commented Aug 14, 2024

Copy link

gitnotebooks bot commented Aug 14, 2024

Found 1 changed notebook. Review the changes at https://gitnotebooks.com/elastic/elasticsearch-labs/pull/317

@maxhniebergall maxhniebergall marked this pull request as ready for review August 28, 2024 20:09
@joemcelroy
Copy link
Member

nitpick: rename the notebook to cohere-elasticsearch-inference-api.ipynb

You also need to exclude this notebook from our tests https://github.com/elastic/elasticsearch-labs/blob/main/bin/find-notebooks-to-test.sh#L3

Will review once CI passes! You might have issue with formatting on CI so follow contributing guide

"source": [
"Now you can instantiate the Python Elasticsearch client.\n",
"\n",
"First provide your password and Cloud ID.\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

This example uses an API key, not a password.

@jeffvestal
Copy link
Contributor

When I ran the ingest step I got an index error. The rest of the notebook worked.

---------------------------------------------------------------------------
BulkIndexError                            Traceback (most recent call last)
[<ipython-input-7-044c75f1a943>](https://localhost:8080/#) in <cell line: 15>()
     16     if i % 1000 == 999:
     17         print(i, "of", 13000)
---> 18         print(helpers.bulk(client, documents))  # Use the bulk endpoint to index
     19         print("last doc:", documents[-1])
     20         documents = []

3 frames
[/usr/local/lib/python3.10/dist-packages/elasticsearch/helpers/actions.py](https://localhost:8080/#) in _process_bulk_chunk_success(resp, bulk_data, ignore_status, raise_on_error)
    272 
    273     if errors:
--> 274         raise BulkIndexError(f"{len(errors)} document(s) failed to index.", errors)
    275 
    276 

BulkIndexError: 305 document(s) failed to index.

@jeffvestal
Copy link
Contributor

Looks good!
My only small suggestion, take or leave it, would be to explain the last part a little more. You do above the cell but inline comments may help people unfamiliar with this type of content

Something like

...
# Use semantic search with our previously configured reranker to find the best set of matching recipes
    recipes = extract_recipe_as_string(semantic_search_with_reranking(query))

    if len(recipes) > 0:
        # if there are one or more recipes that match, combine them together in a string along with our "personal assistant" instructions
        input.append("Recipes:" + "\n\n".join(recipes))

        # pass the full combined instructions and recipes to the Command+R model 
        chat_completion = client.inference.inference(
            inference_id="cohere_completion", input="\n\n\n".join(input)
        )

        # print the response for the user to answer their recipe question
        print(chat_completion["completion"][0]["result"])
    else:
        print("No hits")```

@maxhniebergall
Copy link
Member Author

@jeffvestal , were you using a cohere production API key or a trial key?

@jeffvestal
Copy link
Contributor

@jeffvestal , were you using a cohere production API key or a trial key?

I think it was a prod key, but let me run through it again with a new prod key to double-check.

@maxhniebergall
Copy link
Member Author

Thanks! I am just trying to think of reasons that some of the documents would fail to ingest. It worked every time I tried it.

@jeffvestal
Copy link
Contributor

Alright, @maxhniebergall it must have been me using the wrong key 🫠
I ran it again on a fresh serverless es project with a new prod cohere key and it worked with no errors!

@maxhniebergall
Copy link
Member Author

Thanks Jeff!

@joemcelroy joemcelroy merged commit 057f663 into main Aug 29, 2024
2 of 5 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.

3 participants