Skip to content

Commit 0e834f5

Browse files
pk-zipstackclaudepre-commit-ci[bot]
authored
UN-2967 [FIX] - Fix Repeated Embedding Call For Zero Chunk Size and Multiple Prompts (#1682)
* [MISC] - Update Tool Versions Bumped tool versions: - Classifier: 0.0.70 → 0.0.71 - Structure: 0.0.90 → 0.0.91 - Text Extractor: 0.0.66 → 0.0.67 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fixed extra embedding calls while chunking is zero * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Claude <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3512d89 commit 0e834f5

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

prompt-service/src/unstract/prompt_service/controllers/answer_prompt.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,24 @@ def prompt_processor() -> Any:
149149
capture_metrics=True,
150150
)
151151

152-
embedding = EmbeddingCompat(
153-
adapter_instance_id=output[PSKeys.EMBEDDING],
154-
tool=util,
155-
kwargs={
156-
**usage_kwargs,
157-
},
158-
)
152+
# Only create embedding and vector_db if chunk_size > 0
153+
# When chunk_size is 0, we read the complete file without embeddings
154+
embedding = None
155+
vector_db = None
156+
if chunk_size > 0:
157+
embedding = EmbeddingCompat(
158+
adapter_instance_id=output[PSKeys.EMBEDDING],
159+
tool=util,
160+
kwargs={
161+
**usage_kwargs,
162+
},
163+
)
159164

160-
vector_db = VectorDB(
161-
tool=util,
162-
adapter_instance_id=output[PSKeys.VECTOR_DB],
163-
embedding=embedding,
164-
)
165+
vector_db = VectorDB(
166+
tool=util,
167+
adapter_instance_id=output[PSKeys.VECTOR_DB],
168+
embedding=embedding,
169+
)
165170
except SdkError as e:
166171
msg = f"Couldn't fetch adapter. {e}"
167172
app.logger.error(msg)
@@ -384,7 +389,7 @@ def prompt_processor() -> Any:
384389
output=output,
385390
doc_id=doc_id,
386391
llm=llm,
387-
vector_db=vector_db,
392+
vector_db=vector_db, # This will be None when chunk_size is 0
388393
retrieval_type=retrieval_strategy,
389394
metadata=metadata,
390395
chunk_size=chunk_size,
@@ -657,7 +662,9 @@ def prompt_processor() -> Any:
657662
**challenge_metrics,
658663
}
659664
)
660-
vector_db.close()
665+
# Only close vector_db if it was created (chunk_size > 0)
666+
if vector_db:
667+
vector_db.close()
661668
publish_log(
662669
log_events_id,
663670
{"tool_id": tool_id, "doc_name": doc_name},

prompt-service/src/unstract/prompt_service/services/indexing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def index(
5151
tool=util,
5252
fs=fs_instance,
5353
)
54+
55+
# Skip embedding creation and indexing when chunk_size is 0
56+
# When chunk_size is 0, we don't need vector operations
57+
if chunking_config.chunk_size == 0:
58+
logger.info(f"Skipping indexing for chunk_size=0. Doc ID: {doc_id}")
59+
return doc_id
60+
5461
embedding = EmbeddingCompat(
5562
adapter_instance_id=instance_identifiers.embedding_instance_id,
5663
tool=util,

0 commit comments

Comments
 (0)