Skip to content

Commit 7468dde

Browse files
feat: add param extra_payload for VectorRetriever.process() (#1161)
Co-authored-by: Wendong <[email protected]>
1 parent 768dc3d commit 7468dde

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

camel/retrievers/vector_retriever.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def process(
7676
max_characters: int = 500,
7777
embed_batch: int = 50,
7878
should_chunk: bool = True,
79+
extra_info: Optional[dict] = None,
7980
**kwargs: Any,
8081
) -> None:
8182
r"""Processes content from local file path, remote URL, string
@@ -93,6 +94,8 @@ def process(
9394
embed_batch (int): Size of batch for embeddings. Defaults to `50`.
9495
should_chunk (bool): If True, divide the content into chunks,
9596
otherwise skip chunking. Defaults to True.
97+
extra_info (Optional[dict]): Extra information to be added
98+
to the payload. Defaults to None.
9699
**kwargs (Any): Additional keyword arguments for content parsing.
97100
"""
98101
from unstructured.documents.elements import Element
@@ -153,12 +156,13 @@ def process(
153156
chunk_metadata = {"metadata": chunk.metadata.to_dict()}
154157
# Remove the 'orig_elements' key if it exists
155158
chunk_metadata["metadata"].pop("orig_elements", "")
156-
159+
extra_info = extra_info or {}
157160
chunk_text = {"text": str(chunk)}
158161
combined_dict = {
159162
**content_path_info,
160163
**chunk_metadata,
161164
**chunk_text,
165+
**extra_info,
162166
}
163167

164168
records.append(

test/retrievers/test_cohere_rerank_retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_query(cohere_rerank, mock_retrieved_result):
9999
query=query, retrieved_result=mock_retrieved_result, top_k=1
100100
)
101101
assert len(result) == 1
102-
assert result[0]["similarity score"] == 0.9999998
102+
assert result[0]["similarity score"] == 0.9999999
103103
assert (
104104
'by Isaac Asimov in his science fiction stories' in result[0]["text"]
105105
)

0 commit comments

Comments
 (0)