Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Indexing/Summarization fails with Pinecone inconsistently (#358)

Gayathri5eb85788637e
diff --git a/backend/prompt_studio/prompt_studio_output_manager/output_manager_helper.py b/backend/prompt_studio/prompt_studio_output_manager/output_manager_helper.py
index 5f2daba73..6f942e3b7 100644
--- a/backend/prompt_studio/prompt_studio_output_manager/output_manager_helper.py
+++ b/backend/prompt_studio/prompt_studio_output_manager/output_manager_helper.py
@@ -81,7 +81,9 @@ class OutputManagerHelper:
args: dict[str, str] = dict()
args["run_id"] = run_id
- # Update the record with the run id
+ args["output"] = output
+ args["eval_metrics"] = eval_metrics
+ # Update the record with the run id and other params
PromptStudioOutputManager.objects.filter(
document_manager=document_manager,
tool_id=tool,
diff --git a/prompt-service/src/unstract/prompt_service/main.py b/prompt-service/src/unstract/prompt_service/main.py
index 85dd2adf5..c960e079c 100644
--- a/prompt-service/src/unstract/prompt_service/main.py
+++ b/prompt-service/src/unstract/prompt_service/main.py
@@ -1,3 +1,4 @@
+import time
import traceback
from enum import Enum
from json import JSONDecodeError
@@ -297,24 +298,39 @@ def prompt_processor() -> Any:
doc_id=doc_id,
usage_kwargs=usage_kwargs,
)
- if context is None:
- # TODO: Obtain user set name for vector DB
- msg = "Couldn't fetch context from vector DB"
- app.logger.error(
- f"{msg} {output[PSKeys.VECTOR_DB]} for doc_id {doc_id}"
+ if not context:
+ # UN-1288 For Pinecone, we are seeing an inconsistent case where
+ # query with doc_id fails even though indexing just happened.
+ # This causes the following retrieve to return no text.
+ # To rule out any lag on the Pinecone vector DB write,
+ # the following sleep is added.
+ # Note: This will not fix the issue. Since this issue is inconsistent
+ # and not reproducible easily, this is just a safety net.
+ time.sleep(2)
+ context: Optional[str] = tool_index.get_text_from_index(
+ embedding_instance_id=output[PSKeys.EMBEDDING],
+ vector_db_instance_id=output[PSKeys.VECTOR_DB],
+ doc_id=doc_id,
+ usage_kwargs=usage_kwargs,
)
- _publish_log(
- log_events_id,
- {
- "tool_id": tool_id,
- "prompt_key": prompt_name,
- "doc_name": doc_name,
- },
- LogLevel.ERROR,
- RunLevel.RUN,
- msg,
- )
- raise APIError(message=msg)
+ if context is None:
+ # TODO: Obtain user set name for vector DB
+ msg = "Couldn't fetch context from vector DB"
+ app.logger.error(
+ f"{msg} {output[PSKeys.VECTOR_DB]} for doc_id {doc_id}"
+ )
+ _publish_log(
+ log_events_id,
+ {
+ "tool_id": tool_id,
+ "prompt_key": prompt_name,
+ "doc_name": doc_name,
+ },
+ LogLevel.ERROR,
+ RunLevel.RUN,
+ msg,
+ )
+ raise APIError(message=msg)
# TODO: Use vectorDB name when available
_publish_log(
log_events_id,
@@ -681,6 +697,17 @@ def run_retrieval( # type:ignore
)
context = _retrieve_context(output, doc_id, vector_index, prompt)
+ if not context:
+ # UN-1288 For Pinecone, we are seeing an inconsistent case where
+ # query with doc_id fails even though indexing just happened.
+ # This causes the following retrieve to return no text.
+ # To rule out any lag on the Pinecone vector DB write,
+ # the following sleep is added
+ # Note: This will not fix the issue. Since this issue is inconsistent
+ # and not reproducible easily, this is just a safety net.
+ time.sleep(2)
+ context = _retrieve_context(output, doc_id, vector_index, prompt)
+
answer = construct_and_run_prompt( # type:ignore
output,
llm,