patterns-ai-core / langchainrb

Build LLM-powered applications in Ruby
https://rubydoc.info/gems/langchainrb
MIT License
1.43k stars 194 forks source link

Add the `ask()` method to our `Langchain::ActiveRecord::Hooks` #345

Closed andreibondarev closed 1 year ago

andreibondarev commented 1 year ago

Motivation

We'd like to expose the ask() method so that you can utilize the RAG (Retrieval Augmented Generation) flow when operating on the ActiveRecord model.

Steps

In the Langchain::ActiveRecord::Hooks class, similar to the similarity_search() method we should expose the ask() method. This method should be just forwarding the ask() method along to the vectorsearch provider. You can see how the ask() method works by looking at any of the implementations inside of the vectorsearch/* classes.

Expected behavior:

Recipe.ask(question: "...")

# Top results are fetched from the vectorsearch DB and inserted as a context

# LLM produces a response
andreibondarev commented 1 year ago

@yorzi Want to take a stab at this?

yorzi commented 1 year ago

@andreibondarev Yeah, let me start from this one.