zmedelis / bosquet

Tooling to build LLM applications: prompt templating and composition, agents, LLM memory, and other instruments for builders of AI applications.
https://zmedelis.github.io/bosquet/
Eclipse Public License 1.0
280 stars 19 forks source link

support function(s) to calculate similar texts to given texts ? #13

Closed behrica closed 1 year ago

behrica commented 1 year ago

One key required of using LLMs with longer texts is to "find for a given text similar texts somehow". Having this would allow templates such as:

Given the following text snippets
{% for t in similar %}
{{t}}
{% endfor %}   
answer the following question:   
{{question}}
{% llm-generate } 

together with code such as:

(def question "What is the capital of Germany")
(def similar-snippets (xxxxx/similar question ...))    ;; not existing function
(gen/complete-template capital-template {:question question
                                         :similar similar-snippets})

Fn "similar" would simply return a list of semantic similar texts to a given text (likely using embeddings and a vector database) More then one implementation possible.

In this way we would

not sure, if this requires any new code in bosquet. A concrete implementation of "similar" depends for sure on the underlying vector store, if used

behrica commented 1 year ago

I though about this and for the moment I don't think new code in bosque is required. A bosquet user can implement his own function for finding similar text to a given text and inject those into a template. This is what vector databases allow to do via API call,

Having an "abstraction" for this in bosquet would not be idiomatic for clojure, I think