Skip to content

Commit 4fc3284

Browse files
committed
feat: extend VectorStore parameters
Signed-off-by: Tomáš Dvořák <toomas2d@gmail.com>
1 parent 85bb9bb commit 4fc3284

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

python/beeai_framework/adapters/langchain/backend/vector_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def __init__(self, *, vector_store: LCVectorStore) -> None:
3030
super().__init__()
3131
self.vector_store: LCVectorStore = vector_store
3232

33-
async def add_documents(self, documents: list[Document]) -> list[str]:
33+
async def add_documents(self, documents: list[Document], **kwargs: Any) -> list[str]:
3434
lc_documents = [document_to_lc_document(document) for document in documents]
35-
return await self.vector_store.aadd_documents(lc_documents)
35+
return await self.vector_store.aadd_documents(lc_documents, **kwargs)
3636

3737
async def search(self, query: QueryLike, k: int = 4, **kwargs: Any) -> list[DocumentWithScore]:
3838
query_str = str(query)

python/beeai_framework/adapters/langchain/mappers/documents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414

1515
def lc_document_to_document(lc_document: Document) -> VectorStoreDocument:
16-
return VectorStoreDocument(content=lc_document.page_content, metadata=lc_document.metadata)
16+
return VectorStoreDocument(id=lc_document.id, content=lc_document.page_content, metadata=lc_document.metadata)
1717

1818

1919
def document_to_lc_document(document: VectorStoreDocument) -> Document:
20-
return Document(page_content=document.content, metadata=document.metadata)
20+
return Document(id=document.id, page_content=document.content, metadata=document.metadata)

python/beeai_framework/backend/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,19 @@ class EmbeddingModelOutput(BaseModel):
247247

248248

249249
class Document(BaseModel):
250+
model_config = ConfigDict(extra="allow")
251+
252+
id: str | None = Field(default=None, coerce_numbers_to_str=True)
253+
metadata: dict[str, str | int | float | bool] = Field(default_factory=dict)
250254
content: str
251-
metadata: dict[str, str | int | float | bool]
252255

253256
def __str__(self) -> str:
254257
return self.content
255258

256259

257260
class DocumentWithScore(BaseModel):
261+
model_config = ConfigDict(extra="allow")
262+
258263
document: Document
259264
score: float
260265

python/beeai_framework/tools/search/retrieval/vector_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def _run(
4949
self, input: VectorStoreSearchToolInput, options: ToolRunOptions | None, context: RunContext
5050
) -> VectorStoreSearchToolOutput:
5151
# Search the vector store using the provided query and parameters
52-
documents_with_score = await self.vector_store.search(query=input.query, k=input.k)
52+
documents_with_score = await self.vector_store.search(**input.model_dump())
5353

5454
# Convert DocumentWithScore objects to SearchToolResult format
5555
results = [

0 commit comments

Comments
 (0)