|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | module Langchain::Vectorsearch |
| 4 | + # |
| 5 | + # Wrapper around Elasticsearch vector search capabilities. |
| 6 | + # |
| 7 | + # Setting up Elasticsearch: |
| 8 | + # 1. Get Elasticsearch up and running with Docker: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html |
| 9 | + # 2. Copy the HTTP CA certificate SHA-256 fingerprint and set the ELASTICSEARCH_CA_FINGERPRINT environment variable |
| 10 | + # 3. Set the ELASTICSEARCH_URL environment variable |
| 11 | + # |
| 12 | + # Gem requirements: |
| 13 | + # gem "elasticsearch", "~> 8.0.0" |
| 14 | + # |
| 15 | + # Usage: |
| 16 | + # llm = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"]) |
| 17 | + # es = Langchain::Vectorsearch::Elasticsearch.new( |
| 18 | + # url: ENV["ELASTICSEARCH_URL"], |
| 19 | + # index_name: "docs", |
| 20 | + # llm: llm, |
| 21 | + # es_options: { |
| 22 | + # transport_options: {ssl: {verify: false}}, |
| 23 | + # ca_fingerprint: ENV["ELASTICSEARCH_CA_FINGERPRINT"] |
| 24 | + # } |
| 25 | + # ) |
| 26 | + # |
| 27 | + # es.create_default_schema |
| 28 | + # es.add_texts(texts: ["..."]) |
| 29 | + # es.similarity_search(text: "...") |
| 30 | + # |
4 | 31 | class Elasticsearch < Base |
5 | | - # |
6 | | - # Wrapper around Elasticsearch vector search capabilities. |
7 | | - # |
8 | | - # Setting up Elasticsearch: |
9 | | - # 1. Get Elasticsearch up and running with Docker: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html |
10 | | - # 2. Copy the HTTP CA certificate SHA-256 fingerprint and set the ELASTICSEARCH_CA_FINGERPRINT environment variable |
11 | | - # 3. Set the ELASTICSEARCH_URL environment variable |
12 | | - # |
13 | | - # Gem requirements: |
14 | | - # gem "elasticsearch", "~> 8.0.0" |
15 | | - # |
16 | | - # Usage: |
17 | | - # llm = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"]) |
18 | | - # es = Langchain::Vectorsearch::Elasticsearch.new( |
19 | | - # url: ENV["ELASTICSEARCH_URL"], |
20 | | - # index_name: "docs", |
21 | | - # llm: llm, |
22 | | - # es_options: { |
23 | | - # transport_options: {ssl: {verify: false}}, |
24 | | - # ca_fingerprint: ENV["ELASTICSEARCH_CA_FINGERPRINT"] |
25 | | - # } |
26 | | - # ) |
27 | | - # |
28 | | - # es.create_default_schema |
29 | | - # es.add_texts(texts: ["..."]) |
30 | | - # es.similarity_search(text: "...") |
31 | | - # |
32 | 32 | attr_accessor :es_client, :index_name, :options |
33 | 33 |
|
34 | 34 | def initialize(url:, index_name:, llm:, api_key: nil, es_options: {}) |
|
0 commit comments