elastic / blog-langchain-elasticsearch Goto Github PK
View Code? Open in Web Editor NEWCode examples accompanying blog "Privacy-first AI search using LangChain and Elasticsearch"
License: Apache License 2.0
Code examples accompanying blog "Privacy-first AI search using LangChain and Elasticsearch"
License: Apache License 2.0
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')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.