Skip to content

Commit

Permalink
[FIX] Removing preamble from embedding retrieval prompt (#539)
Browse files Browse the repository at this point in the history
* Removing preamble from embedding retrival prompt

* retaining node score to 0

---------

Co-authored-by: Deepak K <[email protected]>
  • Loading branch information
harini-venkataraman and Deepak-Kesavan authored Jul 31, 2024
1 parent ab4901d commit eb64aab
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions prompt-service/src/unstract/prompt_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,6 @@ def construct_prompt(
return prompt


def construct_prompt_for_engine(
preamble: str,
prompt: str,
postamble: str,
grammar_list: list[dict[str, Any]],
) -> str:
# Let's cleanup the context. Remove if 3 consecutive newlines are found
prompt = f"{preamble}\n\nQuestion or Instruction: {prompt}\n"
if grammar_list is not None and len(grammar_list) > 0:
prompt += "\n"
for grammar in grammar_list:
word = ""
synonyms = []
if PSKeys.WORD in grammar:
word = grammar[PSKeys.WORD]
if PSKeys.SYNONYMS in grammar:
synonyms = grammar[PSKeys.SYNONYMS]
if len(synonyms) > 0 and word != "":
prompt += f'\nNote: You can consider that the word {word} is same as \
{", ".join(synonyms)} in both the quesiton and the context.' # noqa
prompt += f"\n\n{postamble}"
prompt += "\n\n"
return prompt


def authentication_middleware(func: Any) -> Any:
def wrapper(*args: Any, **kwargs: Any) -> Any:
token = AuthenticationMiddleware.get_token_from_auth_header(request)
Expand Down Expand Up @@ -703,13 +678,8 @@ def run_retrieval( # type:ignore
vector_index,
retrieval_type: str,
) -> tuple[str, str]:
prompt = construct_prompt_for_engine(
preamble=tool_settings.get(PSKeys.PREAMBLE, ""),
prompt=output[PSKeys.PROMPTX],
postamble=tool_settings.get(PSKeys.POSTAMBLE, ""),
grammar_list=tool_settings.get(PSKeys.GRAMMAR, []),
)
if retrieval_type is PSKeys.SUBQUESTION:
prompt = output[PSKeys.PROMPTX]
if retrieval_type == PSKeys.SUBQUESTION:
subq_prompt = (
f"Generate a sub-question from the following verbose prompt that will"
f" help extract relevant documents from a vector store:\n\n{prompt}"
Expand Down

0 comments on commit eb64aab

Please sign in to comment.