character-ai/prompt-poet

Prompts in vectorstore?

Opened this issue · 1 comments

If I use a vectorstore for RAG already, and I have a lot of prompts/templates, it's compelling to treat the retrieval of the most suitable system prompt or prompt template like RAG.

Is this something that's easy to set up with prompt Poet?

A potential approach:

I use a vectorstore for RAG already... I have a lot of prompts/templates

As long as the prompts do not rely on interpolating runtime data--I would embed these prompts into your vectorstore.

Create a function that retrieves these prompts from vectorstore given any arbitrary runtime data-- ex. get_rag_prompt(user_query, ...).

Create a main prompt template that takes this function and any runtime data you need to pass to the function.

Within the template, invoke this function and bake the retval into (any number of) prompt parts.

main_template.yml.j2: where retval is a string-like object

{% set rag_prompt = get_rag_prompt(user_query) %}
{% if rag_prompt %}
- name: rag_prompt
  content: |
    {{ rag_prompt }}
{% endif %}

main_template.yml.j2: where retval is a list of string-like objects

{% set rag_prompt = get_rag_prompt(user_query) %}
{% for el in rag_prompt %}
- name: rag_prompt_{{ loop.index }}
  content: |
    {{ el }}
{% endif %}

Alternatively, you can embed the entire prompt poet template (yaml + jinja) and retrieve it but I doubt the semantics of the yaml and jinja will work out.

Open to other ideas!