Giter Site home page Giter Site logo

elastic / elasticsearch-labs Goto Github PK

View Code? Open in Web Editor NEW
503.0 194.0 124.0 83.86 MB

Notebooks & Example Apps for Search & AI Applications with Elasticsearch

Home Page: https://www.elastic.co/search-labs

License: Apache License 2.0

JavaScript 1.36% Handlebars 0.08% Python 3.22% HTML 0.60% Dockerfile 0.08% Shell 0.16% TypeScript 1.89% CSS 0.16% Jupyter Notebook 92.43% Makefile 0.02%
ai chatgpt chatlog elastic elasticsearch genai genaistack openai openai-chatgpt search

elasticsearch-labs's Introduction

Elasticsearch Examples & Apps

Visit Search Labs for the latest articles and tutorials on using Elasticsearch for search and AI/ML-powered search experiences

This repo contains executable Python notebooks, sample apps, and resources for testing out the Elastic platform:

  • Learn how to use Elasticsearch as a vector database to store embeddings, power hybrid and semantic search experiences.
  • Build use cases such as retrieval augmented generation (RAG), summarization, and question answering (QA).
  • Test Elastic's leading-edge, out-of-the-box capabilities like the Elastic Learned Sparse Encoder and reciprocal rank fusion (RRF), which produce best-in-class results without training or tuning.
  • Integrate with projects like OpenAI, Hugging Face, and LangChain, and use Elasticsearch as the backbone of your LLM-powered applications.

Elastic enables all modern search experiences powered by AI/ML.

Apps

Python notebooks πŸ“’

The notebooks folder contains a range of executable Python notebooks, so you can test these features out for yourself. Colab provides an easy-to-use Python virtual environment in the browser.

Generative AI

Playground RAG Notebooks

Try out Playground in Kibana with the following notebooks:

LangChain

Document Chunking

Search

Integrations

Model Upgrades

Contributing 🎁

See contributing guidelines.

Support πŸ›Ÿ

The Search team at Elastic maintains this repository and is happy to help.

Official Support Services

If you have an Elastic subscription, you are entitled to Support services for your Elasticsearch deployment. See our welcome page for working with our support team. These services do not apply to the sample application code contained in this repository.

Discuss Forum

Try posting your question to the Elastic discuss forums and tag it with #esre-elasticsearch-relevance-engine

Elastic Slack

You can also find us in the #search-esre-relevance-engine channel of the Elastic Community Slack

License βš–οΈ

This software is licensed under the Apache License, version 2 ("ALv2").

elasticsearch-labs's People

Contributors

afoucret avatar ashishtiwari1993 avatar demjened avatar hemantmalik avatar jeffvestal avatar jessicagarson avatar joemcelroy avatar joshdevins avatar leemthompo avatar lio-p avatar m-adams avatar markjhoy avatar maxjakob avatar miguelgrinberg avatar mikep86 avatar pquentin avatar priscillaparodi avatar saarikabhasi avatar salgado avatar samiul-thesoccerfan avatar seanstory avatar serenachou avatar sphilipse avatar sunilemanjee avatar szabosteve avatar tattdcodemonkey avatar timgrein avatar valerioarvizzigno avatar wonseop avatar yansavitski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elasticsearch-labs's Issues

CI notebook failures possibly due to new Langchain integration

There are two tests from our CI that are now failing, presumably after they started using the updated langchain integration.

The errors:

Running notebooks/document-chunking/with-langchain-splitters.ipynb... Failed
...
BadRequestError: BadRequestError(400, 'x_content_parse_exception', "[1:117] [text_embedding] model_id doesn't support values of type: VALUE_NULL")
Running notebooks/langchain/langchain-using-own-model.ipynb... Failed
...
AttributeError: 'ElasticsearchStore' object has no attribute 'client'

@maxjakob any ideas?

Complete run with these failures: https://github.com/elastic/elasticsearch-labs/actions/runs/9113170450

chatbot-rag-app does not work for self-signed (local development)

For self-signed environment, the code does not work. we need to set the certificate in order to establish a connection with Elasticsearch. There are two places to change:

  1. index_data.py
ELASTCSEARCH_CERT_PATH = "/usr/share/certs/http_ca.crt"

if ELASTICSEARCH_URL:
    elasticsearch_client = Elasticsearch(
        hosts=[ELASTICSEARCH_URL], 
        ca_certs = ELASTCSEARCH_CERT_PATH, 
        verify_certs = True
    )
This adds the certificate info into the connection.
  1. elasticsearch-client.py
ELASTCSEARCH_CERT_PATH = "/usr/share/certs/http_ca.crt"


if ELASTICSEARCH_URL:
    elasticsearch_client = Elasticsearch(
        hosts=[ELASTICSEARCH_URL], 
        ca_certs = ELASTCSEARCH_CERT_PATH, 
        verify_certs = True
    )

We can index the data using the command like:

docker run \
  --volume="$PWD/http_ca.crt:/usr/share/certs/http_ca.crt:ro" \
  --rm --env-file .env chatbot-rag-app flask create-index

and we can run the frondend like:

docker run \
  --volume="$PWD/http_ca.crt:/usr/share/certs/http_ca.crt:ro" \
  --rm -p 4000:4000 --env-file .env -d chatbot-rag-app

Confusion about the use of self-hosted Elasticsearch with ELSER in RAG App

Hello,

the documentation for the RAG app mentions that it is possible to use a self-hosted Elasticsearch instance. However, the use of ELSER seems to be necessary for the application to work.

Can you please clarify if and how a self-hosted Elasticsearch instance can be used without ELSER? In particular, it would be helpful to know whether a cloud instance or special ELSER configurations are required to fully utilise the RAG app.

Thank you very much for your support and clarification!

Wrong dims in the model configuration for embed-english-v3.0 in Cohere notebook

I tried to run the cohere notebook at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/cohere/cohere-elasticsearch.ipynb. In the code, it configures:

client.indices.create(
    index="cohere-embeddings",
    settings={"index": {"default_pipeline": "cohere_embeddings"}},
    mappings={
        "properties": {
            "text_embedding": {
                "type": "dense_vector",
                "dims": 1024,
                "element_type": "byte",
            },
            "text": {"type": "text"},
            "id": {"type": "integer"},
            "title": {"type": "text"},
        }
    },
)

When I run the code for the model, and finally index data into Elasticsearch. It complains:

{
  "error": {
    "root_cause": [
      {
        "type": "document_parsing_exception",
        "reason": "[1:2078] failed to parse: The [dense_vector] field [text_embedding] in doc [document with id '4983'] has a different number of dimensions [384] than defined in the mapping [1024]"
      }
    ],
    "type": "document_parsing_exception",
    "reason": "[1:2078] failed to parse: The [dense_vector] field [text_embedding] in doc [document with id '4983'] has a different number of dimensions [384] than defined in the mapping [1024]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "The [dense_vector] field [text_embedding] in doc [document with id '4983'] has a different number of dimensions [384] than defined in the mapping [1024]"
    }
  },
  "status": 400
}

From the error returned, the dims for the model is 384 instead of 1024. I think the documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/cohere-es.html is also wrong. After I reconfigure it to 384, and it works.

inference id is wrongly written when creating the model

I just ran the notebook at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/cohere/cohere-elasticsearch.ipynb. It was not successful. I found that the inference id was not so correct.

client.inference.put_model(
    task_type="text_embedding",
    inference_id="cohere_embeddings1",
    body={
        "service": "cohere",
        "service_settings": {
            "api_key": COHERE_API_KEY,
            "model_id": "embed-english-v3.0",
            "embedding_type": "byte",
        },
    },
)

It defines the inference_id as "cohere_embeddings1", however, it is never referred in other part of the codes. I found our tutorial at https://www.elastic.co/guide/en/elasticsearch/reference/current/cohere-es.html. The correct code is:

COHERE_API_KEY = "cohere_api_key"

client.inference.put_model(
    task_type="text_embedding",
    inference_id="cohere_embeddings",
    body={
        "service": "cohere",
        "service_settings": {
            "api_key": COHERE_API_KEY,
            "model_id": "embed-english-v3.0",
            "embedding_type": "byte"
        }
    },
)

image

What is the reason for "elasticsearch.BadRequestError: BadRequestError(400, 'x_content_parse_exception', '[1:137] unknown field [xlm_roberta]')"?

  1. What do I want?

    I want to install an additional NLP model to Elasticsearch. The model is called multilingual-e5-base.

  2. What did I do?

    Therefore, I followed the steps in Elasticsearch
    documentation
    .

  3. What I expected?

    The multilingual-e5-base is successfully installed.

  4. What I tried?

Here is the relevant section in my Python Notebook for the installation:

!source ../.env && \
eland_import_hub_model \
    --url ${REMOTE_HOST} \
    --es-username ${USER} \
    --es-password ${API_KEY} \
    --hub-model-id intfloat/multilingual-e5-base \
    --es-model-id multilingual-e5-base \
    --task-type text_embedding \
    --start

Error message:

raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.BadRequestError: BadRequestError(400, 'x_content_parse_exception', '[1:137] unknown field [xlm_roberta]')

Note: I posted the same question on stackoverflow link

inference search notebook error with model_id vs inference_id after 8.13 upgrade

Issue from @derickson

My environment

The Semantic search step uses the follwing as it's knn query

{
        "field": "plot_embedding",
        "query_vector_builder": {
            "text_embedding": {
                "inference_id": "my_openai_embedding_model",
                "model_text": "Fighting movie",
            }
        },
        "k": 10,
        "num_candidates": 100,
    }

which does not work in 8.13

changing to "model_id" instead of "inference_id" solves the issue. This notebook was written for 8.12

the note at the end is innacurate

"NOTE: If you use Elasticsearch 8.12, you must change inference_id in the snippet above to model_id."

First error reason: Could not find trained model [.elser_model_1] when trying workplace-search

Can't execute index-data.py

step to reproduce

  1. clone repo
  2. cd workplace-search
  3. install requirements.txt
  4. Cange ES Client connection to http://localhost:9200
  5. run index-data.py

Loaded 1 documents
Split 1 documents into 104 chunks
Creating Elasticsearch sparse vector store in Elastic Cloud: None
Error adding texts: 104 document(s) failed to index.
First error reason: Could not find trained model [.elser_model_1]
Traceback (most recent call last):
File "/home/aleksei/code/elasticsearch-labs/example-apps/workplace-search/./data/index-data.py", line 52, in
ElasticsearchStore.from_documents(
File "/home/aleksei/.local/lib/python3.10/site-packages/langchain/vectorstores/elasticsearch.py", line 1125, in from_documents
elasticsearchStore.add_documents(documents, bulk_kwargs=bulk_kwargs)
File "/home/aleksei/.local/lib/python3.10/site-packages/langchain/schema/vectorstore.py", line 122, in add_documents
return self.add_texts(texts, metadatas, **kwargs)
File "/home/aleksei/.local/lib/python3.10/site-packages/langchain/vectorstores/elasticsearch.py", line 971, in add_texts
raise e
File "/home/aleksei/.local/lib/python3.10/site-packages/langchain/vectorstores/elasticsearch.py", line 954, in add_texts
success, failed = bulk(
File "/home/aleksei/.local/lib/python3.10/site-packages/elasticsearch/helpers/actions.py", line 521, in bulk
for ok, item in streaming_bulk(
File "/home/aleksei/.local/lib/python3.10/site-packages/elasticsearch/helpers/actions.py", line 436, in streaming_bulk
for data, (ok, info) in zip(
File "/home/aleksei/.local/lib/python3.10/site-packages/elasticsearch/helpers/actions.py", line 355, in _process_bulk_chunk
yield from gen
File "/home/aleksei/.local/lib/python3.10/site-packages/elasticsearch/helpers/actions.py", line 274, in _process_bulk_chunk_success
raise BulkIndexError(f"{len(errors)} document(s) failed to index.", errors)
elasticsearch.helpers.BulkIndexError: 104 document(s) failed to index.

Model id is needed to get Gemma LLM locally working on private data

This is the code https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/gemma/rag-gemma-huggingface-elastic.ipynb.

There are two improvements here:

  1. For package installation, pytorch is needed. We need to add "torch" module into the list
  2. Since .elser_model_2 has been released, and it is the GA release for use. The following code:
es = ElasticsearchStore.from_documents(
    docs,
    es_cloud_id=ELASTIC_CLOUD_ID,
    es_api_key=ELASTIC_API_KEY,
    index_name=elastic_index_name,
    strategy=ElasticsearchStore.SparseVectorRetrievalStrategy(),
)

works only for .elser_model_1. In order to get it working for .elser_model_2, we have to pass the model id into the strategy:

es = ElasticsearchStore.from_documents(
    docs,
    es_cloud_id=ELASTIC_CLOUD_ID,
    es_api_key=ELASTIC_API_KEY,
    index_name=elastic_index_name,
    strategy=ElasticsearchStore.SparseVectorRetrievalStrategy(model_id=".elser_model_2"),
)

If we run the code without the model_id set and we have the .elser_model_2 deployed in the cluster, we might run into a problem reported here at langchain-ai/langchain#18917 even we later on correctly set the model_id in the function call.

AUTO_BUCKET is not working in the ES|QL notebook

For the notebook at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/esql/esql-getting-started.ipynb, the following code is not working:

esql_query = """
FROM sample_data
| KEEP @timestamp
| EVAL bucket = AUTO_BUCKET(@timestamp, 24, "2023-10-23T00:00:00Z", "2023-10-23T23:59:59Z")
"""
response = client.esql.query(query=esql_query)
format_response(response)

The error message is shown as:

BadRequestError: BadRequestError(400, 'verification_exception', 'Found 1 problem\nline 4:17: Unknown function [AUTO_BUCKET], did you mean [bucket]?')

![image](https://github.com/elastic/elasticsearch-labs/assets/8455957/be2018cb-a9dd-46fd-a281-30b0c9de00c9)

Ragas and Elasticsearch

I've built a Streamlit based RAG pipeline workbench that lets developers experiment using different prompt techniques, LLMs, model temperatures, and document chunking approaches. The results are objectively measured and compared using Ragas and exported to Elastic for visualisation using a dashboard that is part of the repo and can be imported by the user. I've also included LLM interaction logging as part of the app in order to help developers keep track of costs and compare the differences between the models they're using. Ultimately I would also like to write a blog around this and I have taken assignment of the search labs ticket of the same title.

Changing examples to use hosts instead of Cloud ID

Most of the examples in this repo use Could ID instead of hosts, while chatting with @miguelgrinberg and @joemcelroy we noticed that we should probably update them.

What is in most examples is something like this:

ELASTIC_CLOUD_ID = getpass("Elastic Cloud ID: ")

# https://www.elastic.co/search-labs/tutorials/install-elasticsearch/elastic-cloud#creating-an-api-key
ELASTIC_API_KEY = getpass("Elastic Api Key: ")

A version of this could be:

# Create an Elasticsearch client instance
client = Elasticsearch(
    getpass("Host: "),  # Securely get the host for the Elasticsearch cluster
    api_key=getpass("API Key: "),  # Securely get the API key for authentication
)

elastic_transport.ConnectionTimeout: Connection timed out

when i run :
python manage.py search_index --rebuild
have always this error :
anaconda3/envs/DJ_ElasticSearch/lib/python3.6/site-packages/elastic_transport/_node/_http_urllib3.py", line 202, in perform_request
raise err from None
elastic_transport.ConnectionTimeout: Connection timed out

How can i solve that?

[chatbot-rag-app] jq failed in Windows

I cannot install packages

  1. clone repo to windows 11
  2. cd example-apps/chatbot-rag-app
  3. conda create-n test_env python=3.11
  4. install requirements.txt
  5. Failed to build jq
Building wheels for collected packages: jq
  Building wheel for jq (pyproject.toml) ... error
  error: subprocess-exited-with-error

  Γ— Building wheel for jq (pyproject.toml) did not run successfully.
  β”‚ exit code: 1
  ╰─> [5 lines of output]
      running bdist_wheel
      running build
      running build_ext
       Executing: ./configure CFLAGS=-fPIC --prefix=C:\Users\wonseop\AppData\Local\Temp\pip-install-tzsfm24e\jq_79650ef0c8804b599c4ca739dc810450\_deps\build\onig-install-6.9.4
      error: [WinError 2] The system cannot find the file specified
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for jq
Failed to build jq
ERROR: Could not build wheels for jq, which is required to install pyproject.toml-based projects

Someone please help me~

Cohere service is not available in the 8.12 release

For the notebook at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/cohere/inference-cohere.ipynb. In the following code:

API_KEY = getpass("Enter Cohere API key:  ")

client.inference.put_model(
    task_type="text_embedding",
    model_id="cohere_embeddings",
    body={
        "service": "cohere",
        "service_settings": {
            "api_key": API_KEY,
            "model_id": "embed-english-v3.0",
            "embedding_type": "int8",
        },
        "task_settings": {},
    },
)

Cohere does not work for Elastic Stack normal release. It returns the following error:

BadRequestError: BadRequestError(400, 'status_exception', 'Unknown service [cohere]')

For Elastic Stack 8.12 installation.

According to our documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html. Currently, only the following services are supported:

ELSER
OpenAI
Hugging Face

According to the reply from our Slack discussion, "Cohere" is only currently supported on Serverless.

It would be good to point out this to the developers.

nbtest fails on document chunking notebook

I'm getting the following error when running the document chunking notebook under nbtest:

ConflictError: ConflictError(409, 'status_exception', 'Trained model deployment [sentence-transformers__all-minilm-l6-v2] is not allocated to any nodes')

This is on a deployment that has never been used with this particular model.

Fetch surrounding chunks notebook

I have built a notebook to demonstrate how to fetch surrounding chunks within Elasticsearch. This is not the only way to do it, but it is definitely a valid approach. I am interested in contributing this notebook to our examples

Notebook: Google Colab

The example uses text from a Harry Potter book, splitting it by chapter and then into chunks. Each chunk is a nested passage containing the text, dense, and sparse representations of the chunk.

When searching, the demo will fetch the matching passage chunk along with surrounding chunks. If the chunk is the first chunk in the chapter, it will fetch n, n+1, and n+2. If it is the last chunk, it will fetch n, n-1, and n-2. Otherwise it will fetch n-1, n, n+1.

Jupyter link in β€œGeospatial search" is broken

Enrich error for "Getting started with ES|QL" notebook

For EQSL getting started notboook at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/esql/esql-getting-started.ipynb. The problem lies here in the following piece of code:

# Define the enrich policy
policy = {
    "match": {
        "indices": "clientips",
        "match_field": "client_ip",
        "enrich_fields": ["env"],
    }
}

# Put the enrich policy
client.enrich.put_policy(name="clientip_policy", body=policy)

# Execute the enrich policy without waiting for completion
client.enrich.execute_policy(name="clientip_policy", wait_for_completion=False)

The policy is executed in asynchronous way, and run the following code immediately, it results error:

esql_query = """
FROM sample_data
| KEEP @timestamp, client_ip, event_duration
| EVAL client_ip = TO_STRING(client_ip)
| ENRICH clientip_policy ON client_ip WITH env
"""
response = client.esql.query(query=esql_query)
format_response(response)

I think the enrich index is not ready. To correct the problem, we need to make the call to synchronous:

client.enrich.execute_policy(name="clientip_policy", wait_for_completion=True)

image

BadRequestError(400, 'parsing_exception', 'Unknown key for a START_OBJECT in [knn].')

Something is wrong with the Hybrid Search query:

results = es.search(
        query={
            "bool": {
                **search_query,
                **filters
            }
        },
        knn={
            "field": "embedding",
            "query_vector": es.get_embedding(parsed_query),
            "k": 10,
           "num_candidates": 50,
        },
        rank={"rrf": {}},
        aggs={
            "category-agg": {
                "terms": {
                    "field": "category.keyword",
                }
            },
            "year-agg": {
                "date_histogram": {
                    "field": "updated_at",
                    "calendar_interval": "year",
                    "format": "yyyy",
                },
            },
        },
        size=5,
        from_=from_,
    )

I get this error:

BadRequestError(400, 'parsing_exception', 'Unknown key for a START_OBJECT in [knn].')

If I delete the knn Param I get this error:

BadRequestError(400, 'parsing_exception', 'Unknown key for a START_OBJECT in [rank].')

If I also delete also rank Param it works.

Can someone help me please?

Search text is not used in the embedding generation

at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/gemini/vector-search-gemini-elastic.ipynb

q = "How's weather in India?"

embedding = genai.embed_content(model=model,
                                content=sample_text,
                                task_type="retrieval_query")

resp = es.search(
  index = elastic_index_name,
  knn={
      "field": "text_embedding",
      "query_vector":  embedding['embedding'],
      "k": 10,
      "num_candidates": 100
    }
)

The variable "q" is never used in the embedding generation in the search process. The correct one should be:

embedding = genai.embed_content(model=model,
                                content=q,
                                task_type="retrieval_query")

Include a note on setting up virtual environments in readme or notebooks

This is a relatively minority "issue" but thinking back to when I started learning python, virtual environments were still "new", it was not covered in most material. Over time I'd built up various quirks that venv would have avoided

Users who are interested in using the notebooks and aren't familiar deeply familiar with python may be able to follow along with the instructions but be unaware that activating a python virtual environment is a good approach to handling dependency issues that can arise when different versions are needed.

Including this somewhere could save a lot of headache and troubleshooting to fix whatever issues arise, while yielding a better user experience.

Potential Addition: Vector and Hybrid search examples in Go

Is there an interest for adding non-Python examples to the labs? Alongside @Anaethelion we're written Go examples to find Gophers in Elasticsearch.

Currently, it's in Markdown format rather than a Python notebook with markdown elements, so it would be good to understand if the search labs blog requires posts in a notebook or can support markdown.

Aware there's been discussion by @xeraa and @joemcelroy so let us know and we can raise a PR to add this contribution. Otherwise, it can live on the Elastic blog instead.

Merge and update corresponding blog post

We'd like to migrate https://www.elastic.co/blog/searching-by-music-leveraging-vector-search-audio-information-retrieval to Search Labs

Which is on the migration list : https://github.com/elastic/search-labs-elastic-co/issues/93 but it already has supporting code in salgado/music-search#1 which I've asked them to open a PR to merge into Search labs. When we migrate the blog over, please update the section of the blog to reference the merged code in Search Labs vs the original GH project.

Get index mapping and Get reference document are inconsistent with noteboook in "OpenAI function calling with Elasticsearch"

I read through the blog at https://www.elastic.co/search-labs/blog/function-calling-with-elastic, and I found two functions defined in the notebook and blog are insconsistent:

  • def get_index_mapping():
  • get_ref_document()

The ones defined in the blogs are not correct:

def get_index_mapping():

    url = f"""{ES_ENDPOINT}/{ES_INDEX}/_mappings"""

    headers = {
        "Content-type": "application/json",
        "Authorization": f"""ApiKey {ES_API_KEY}""",
    }

def get_index_mapping():

    url = f"""{ES_ENDPOINT}/{ES_INDEX}/_mappings"""

    headers = {
        "Content-type": "application/json",
        "Authorization": f"""ApiKey {ES_API_KEY}""",
    }

    resp = requests.request("GET", url, headers=headers)
    resp = json.loads(resp.text)
    mapping = json.dumps(resp, indent=4)

    return mapping

The correct ones are shown in the attached pictures,
image
image

Cusstom ranking method

Hello everyone. I wanted to ask if there's any way that I can implement a custom algorithm for the search when combining KNN and Text Search.

Cloud ID is not properly formatted

  File "/.../elastic/chatbot-rag-app/.venv/lib/python3.11/site-packages/elastic_transport/client_utils.py", line 125, in parse_cloud_id
    raise ValueError("Cloud ID is not properly formatted") from None
ValueError: Cloud ID is not properly formatted

Using the Cloud ID found on my https://cloud.elastic.co/deployments/ page.

It seems that the client_utils.py may be expecting to find a '$' separator in part of the decoded id string.

This prevents ingesting data while attempting to connect to a cloud Elasticsearch instance.

Positional arguments do not work for TransformerModel and wrong pipeline name used in the code for plagiarism demo

For the example app at https://github.com/elastic/elasticsearch-labs/blob/main/supporting-blog-content/plagiarism-detection-with-elasticsearch/plagiarism_detection_es.ipynb. I find there are following issues:

  1. According to code at https://github.com/elastic/eland/blob/main/eland/ml/pytorch/transformers.py,
    class TransformerModel: def __init__( self, *, model_id: str, task_type: str, es_version: Optional[Tuple[int, int, int]] = None, quantize: bool = False, access_token: Optional[str] = None, ):
    It needs to have keyword arguments for the constructor. I am not sure the demo uses which eland version. I use the latest version:
    $ pip3 list | grep eland eland 8.11.1

The call in the code:
tm = TransformerModel(hf_model_id, "text_embedding")

does not work. The working one is:

tm = TransformerModel(model_id=hf_model_id, task_type="text_embedding")

This applies to the code as well:
tm = TransformerModel(hf_model_id, "text_classification")

  1. pipeline name is spelled wrongly in the code:

client.reindex(wait_for_completion=True, source={ "index": "plagiarism-docs" }, dest= { "index": "plagiarism-checker", "pipeline": "plagiarism-pipeline" } )

In the code, "plagiarism-pipeline" pipeline is never created. It should be "plagiarism-checker-pipeline".

  1. The synchronous call for the reindex seems not working at all.

client.reindex(wait_for_completion=True, source={ "index": "plagiarism-docs" }, dest= { "index": "plagiarism-checker", "pipeline": "plagiarism-pipeline" } )

It always returns "Connection time out" error. I have to change it to False to make it work.

GOOGLE_APPLICATION_CREDENTIALS json-service-account-file cannot be found

The application cannot find the json-service-account-file per the given instructions and thus fails on a permission error.
The credential file needs to be copied into one of the directories that is copied into the container by the Dockerfile so it can be found by the app.
My suggestion is to copy the file into the data directory and then set the path accordingly

My suggestion is the following for the Vertex AI Section

Vertex AI

To use Vertex AI you need to set the following environment variables. More info here.

copy your json-service-account-file into the data directory and set the path accordingly

export LLM_TYPE=vertex
export VERTEX_PROJECT_ID=<gcp-project-id>
export VERTEX_REGION=<gcp-region> # Default is us-central1
export GOOGLE_APPLICATION_CREDENTIALS=/data/<json-service-account-file>

"'NoneType' object is not iterable" in the Cohere notebook

In the notebook at https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/integrations/cohere/cohere-elasticsearch.ipynb, in the last part of the code:

response = co.chat(message=query, documents=ranked_documents, model="command-r-plus")

source_documents = []
for citation in response.citations:
   for document_id in citation.document_ids:
       if document_id not in source_documents:
           source_documents.append(document_id)

print(f"Query: {query}")
print(f"Response: {response.text}")

It returns the following error:


`---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[15], line 4
      1 response = co.chat(message=query, documents=ranked_documents, model="command-r-plus")
      3 source_documents = []
----> 4 for citation in response.citations:
      5    for document_id in citation.document_ids:
      6        if document_id not in source_documents:

TypeError: 'NoneType' object is not iterable`

According to the documentation at https://docs.cohere.com/docs/chat-api. There is no such a field "citations" in the Chat API.
image
image

ModuleNotFoundError: No module named 'dotenv' when trying workplace-search

Can't execute index-data.py

step to reproduce

  1. clone repo
  2. cd workplace-search
  3. create virtual env
  4. install requirements.txt
  5. run python3 data/index-data.py

(.venv) aleksei@EPRSBELL001B:~/code/elasticsearch-labs/example-apps/workplace-search$ python3 data/index-data.py
Traceback (most recent call last):
File "/home/aleksei/code/elasticsearch-labs/example-apps/workplace-search/data/index-data.py", line 3, in
from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

chatbot-example does not get the right result as shown in the notebook.

https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/langchain/self-query-retriever-examples/chatbot-example.ipynb

I followed the exact steps as described in the notebook. In the last step, I used the same question, but I got the result "I do not know".
image

However, if I changed the question to "What movies are about dreams and it was released after the year 2009 but before 2011?". Then I will get the exact same result as in the notebook.

image

Unable to run chatbot-rag-app using Azure OpenAI model

I attempted to run the chatbot-rag-app using an Azure OpenAI model, and found that when I entered a question in the prompt box in the GUI, the service would never produce a response.

I was able to successfully use the docker run --rm --env-file .env chatbot-rag-app flask create-index to index the sample documents to my Elasticsearch cluster, so all ES configuration elements are good.

I assumed I was passing a bad var value in the .env file, so I:

  • Double-checked my OPENAI_API_KEY
  • Attempted multiple permutations of OPENAI_VERSION - the model resource overview page in the Azure portal shows a model version of 0613, but the annotation in the project docs indicates that the version should appear like 2023-05-15, so I tried using both 0613 and 2023-06-13, but got the same results with both
  • Double checked the OPENAI_BASE_URL var, using the Endpoint value shown on the Keys & Endpoints page in the azure portal, both with and without the tailing /

Attached are a redacted copy of my .env file (see above for the additional variations I tried), as well as the docker logs from a container instance where this behavior occurred

redacted_dot_env_file.txt
azureopenai_error_logs.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.