Class: Langchain::Tool::Vectorsearch

Inherits:
Object
  • Object
show all
Extended by:
Langchain::ToolDefinition
Defined in:
lib/langchain/tool/vectorsearch.rb

Overview

A tool wraps vectorsearch classes

Usage:

# Initialize the LLM that will be used to generate embeddings
ollama = Langchain::LLM::Ollama.new(url: ENV["OLLAMA_URL"]
chroma = Langchain::Vectorsearch::Chroma.new(url: ENV["CHROMA_URL"], index_name: "my_index", llm: ollama)

# This tool can now be used by the Assistant
vectorsearch_tool = Langchain::Tool::Vectorsearch.new(vectorsearch: chroma)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Langchain::ToolDefinition

define_function, function_schemas, tool_name

Constructor Details

#initialize(vectorsearch:) ⇒ Vectorsearch

Initializes the Vectorsearch tool

Parameters:



28
29
30
# File 'lib/langchain/tool/vectorsearch.rb', line 28

def initialize(vectorsearch:)
  @vectorsearch = vectorsearch
end

Instance Attribute Details

#vectorsearchObject (readonly)

Returns the value of attribute vectorsearch.



23
24
25
# File 'lib/langchain/tool/vectorsearch.rb', line 23

def vectorsearch
  @vectorsearch
end

Instance Method Details

#similarity_search(query:, k: 4) ⇒ Object

Executes the vector search and returns the results

Parameters:

  • query (String)

    The query to search for

  • k (Integer) (defaults to: 4)

    The number of results to return



36
37
38
# File 'lib/langchain/tool/vectorsearch.rb', line 36

def similarity_search(query:, k: 4)
  vectorsearch.similarity_search(query:, k: 4)
end