Skip to content

Commit c48ba31

Browse files
authored
feat: add form bytes (#183)
1 parent 0859fc4 commit c48ba31

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

veadk/knowledgebase/backends/vikingdb_knowledge_backend.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ def add_from_text(self, text: str | list[str], **kwargs) -> bool:
177177
raise ValueError("text must be str or list[str]")
178178
return True
179179

180+
def add_from_bytes(self, content: bytes, file_name: str, **kwargs) -> bool:
181+
"""
182+
Args:
183+
content: bytes, the content to add to knowledgebase, bytes
184+
file_name: str, the file name of the content
185+
**kwargs:
186+
- tos_bucket_name: str, the bucket name of TOS
187+
- tos_bucket_path: str, the path of TOS bucket
188+
"""
189+
tos_bucket_name, tos_bucket_path = _extract_tos_attributes(**kwargs)
190+
tos_url = _upload_bytes_to_tos(
191+
content,
192+
tos_bucket_name=tos_bucket_name,
193+
object_key=f"{tos_bucket_path}/{file_name}",
194+
)
195+
response = self._add_doc(tos_url=tos_url)
196+
if response["code"] == 0:
197+
return True
198+
return False
199+
180200
@override
181201
def search(self, query: str, top_k: int = 5) -> list:
182202
return self._search_knowledge(query=query, top_k=top_k)

0 commit comments

Comments
 (0)