GithubHelp home page GithubHelp logo

elastic / blog-langchain-elasticsearch Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 11.0 734 KB

Code examples accompanying blog "Privacy-first AI search using LangChain and Elasticsearch"

License: Apache License 2.0

Jupyter Notebook 94.14% Python 5.71% Shell 0.15%

blog-langchain-elasticsearch's Issues

ValueError: URL must include a 'scheme', 'host', and 'port' component (ie 'https://localhost:9200') on Colab Notebook

from langchain.vectorstores import ElasticVectorSearch

index_name = "book_wookieepedia_small"

db = ElasticVectorSearch(embedding=hf, elasticsearch_url=es_url, index_name=index_name)

Error

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.10/dist-packages/langchain/vectorstores/elastic_vector_search.py:129 in   │
│ __init__                                                                                         │
│                                                                                                  │
│   126 │   │   self.embedding = embedding                                                         │
│   127 │   │   self.index_name = index_name                                                       │
│   128 │   │   try:                                                                               │
│ ❱ 129 │   │   │   es_client = elasticsearch.Elasticsearch(elasticsearch_url)  # noqa             │
│   130 │   │   except ValueError as e:                                                            │
│   131 │   │   │   raise ValueError(                                                              │
│   132 │   │   │   │   f"Your elasticsearch client string is misformatted. Got error: {e} "       │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/elasticsearch/_sync/client/__init__.py:331 in __init__   │
│                                                                                                  │
│    328 │   │   │   │   │   requests_session_auth = http_auth                                     │
│    329 │   │   │   │   │   http_auth = DEFAULT                                                   │
│    330 │   │   │                                                                                 │
│ ❱  331 │   │   │   node_configs = client_node_configs(                                           │
│    332 │   │   │   │   hosts,                                                                    │
│    333 │   │   │   │   cloud_id=cloud_id,                                                        │
│    334 │   │   │   │   requests_session_auth=requests_session_auth,                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/elasticsearch/_sync/client/utils.py:105 in               │
│ client_node_configs                                                                              │
│                                                                                                  │
│   102 │   │   node_configs = cloud_id_to_node_configs(cloud_id)                                  │
│   103 │   else:                                                                                  │
│   104 │   │   assert hosts is not None                                                           │
│ ❱ 105 │   │   node_configs = hosts_to_node_configs(hosts)                                        │
│   106 │                                                                                          │
│   107 │   # Remove all values which are 'DEFAULT' to avoid overwriting actual defaults.          │
│   108 │   node_options = {k: v for k, v in kwargs.items() if v is not DEFAULT}                   │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/elasticsearch/_sync/client/utils.py:143 in               │
│ hosts_to_node_configs                                                                            │
│                                                                                                  │
│   140 │                                                                                          │
│   141 │   # To make the logic here simpler we reroute everything to be List[X]                   │
│   142 │   if not isinstance(hosts, (tuple, list)):                                               │
│ ❱ 143 │   │   return hosts_to_node_configs([hosts])                                              │
│   144 │                                                                                          │
│   145 │   node_configs: List[NodeConfig] = []                                                    │
│   146 │   for host in hosts:                                                                     │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/elasticsearch/_sync/client/utils.py:151 in               │
│ hosts_to_node_configs                                                                            │
│                                                                                                  │
│   148 │   │   │   node_configs.append(host)                                                      │
│   149 │   │                                                                                      │
│   150 │   │   elif isinstance(host, str):                                                        │
│ ❱ 151 │   │   │   node_configs.append(url_to_node_config(host))                                  │
│   152 │   │                                                                                      │
│   153 │   │   elif isinstance(host, Mapping):                                                    │
│   154 │   │   │   node_configs.append(host_mapping_to_node_config(host))                         │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/elastic_transport/client_utils.py:216 in                 │
│ url_to_node_config                                                                               │
│                                                                                                  │
│   213 │   │   component in (None, "")                                                            │
│   214 │   │   for component in (parsed_url.scheme, parsed_url.host, parsed_port)                 │
│   215 │   ):                                                                                     │
│ ❱ 216 │   │   raise ValueError(                                                                  │
│   217 │   │   │   "URL must include a 'scheme', 'host', and 'port' component (ie 'https://loca   │
│   218 │   │   )                                                                                  │
│   219 │   assert parsed_url.scheme is not None                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: URL must include a 'scheme', 'host', and 'port' component (ie 'https://localhost:9200')

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <cell line: 5>:5                                                                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/langchain/vectorstores/elastic_vector_search.py:131 in   │
│ __init__                                                                                         │
│                                                                                                  │
│   128 │   │   try:                                                                               │
│   129 │   │   │   es_client = elasticsearch.Elasticsearch(elasticsearch_url)  # noqa             │
│   130 │   │   except ValueError as e:                                                            │
│ ❱ 131 │   │   │   raise ValueError(                                                              │
│   132 │   │   │   │   f"Your elasticsearch client string is misformatted. Got error: {e} "
│   133 │   │   │   )                                                                              │
│   134 │   │   self.client = es_client                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Your elasticsearch client string is misformatted. Got error: URL must include a 'scheme', 'host', and 
'port' component (ie 'https://localhost:9200') 

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.