@@ -500,100 +500,6 @@ def _row_to_document(row: Dict[str, Any]) -> Document:
500
500
metadata = row ["metadata" ],
501
501
)
502
502
503
- def get_by_document_id (self , document_id : str ) -> Document | None :
504
- """Get by document ID.
505
-
506
- Args:
507
- document_id: the document ID to get.
508
- """
509
- row = self .table .get (row_id = document_id )
510
- if row is None :
511
- return None
512
- return self ._row_to_document (row = row )
513
-
514
- async def aget_by_document_id (self , document_id : str ) -> Document | None :
515
- """Get by document ID.
516
-
517
- Args:
518
- document_id: the document ID to get.
519
- """
520
- row = await self .table .aget (row_id = document_id )
521
- if row is None :
522
- return None
523
- return self ._row_to_document (row = row )
524
-
525
- def metadata_search (
526
- self ,
527
- metadata : dict [str , Any ] = {}, # noqa: B006
528
- n : int = 5 ,
529
- ) -> Iterable [Document ]:
530
- """Get documents via a metadata search.
531
-
532
- Args:
533
- metadata: the metadata to query for.
534
- """
535
- rows = self .table .find_entries (metadata = metadata , n = n )
536
- return [self ._row_to_document (row = row ) for row in rows if row ]
537
-
538
- async def ametadata_search (
539
- self ,
540
- metadata : dict [str , Any ] = {}, # noqa: B006
541
- n : int = 5 ,
542
- ) -> Iterable [Document ]:
543
- """Get documents via a metadata search.
544
-
545
- Args:
546
- metadata: the metadata to query for.
547
- """
548
- rows = await self .table .afind_entries (metadata = metadata , n = n )
549
- return [self ._row_to_document (row = row ) for row in rows ]
550
-
551
- async def asimilarity_search_with_embedding_id_by_vector (
552
- self ,
553
- embedding : List [float ],
554
- k : int = 4 ,
555
- filter : Optional [Dict [str , str ]] = None ,
556
- body_search : Optional [Union [str , List [str ]]] = None ,
557
- ) -> List [Tuple [Document , List [float ], str ]]:
558
- """Return docs most similar to embedding vector.
559
-
560
- Args:
561
- embedding: Embedding to look up documents similar to.
562
- k: Number of Documents to return. Defaults to 4.
563
- filter: Filter on the metadata to apply.
564
- body_search: Document textual search terms to apply.
565
- Only supported by Astra DB at the moment.
566
- Returns:
567
- List of (Document, embedding, id), the most similar to the query vector.
568
- """
569
- kwargs : Dict [str , Any ] = {}
570
- if filter is not None :
571
- kwargs ["metadata" ] = filter
572
- if body_search is not None :
573
- kwargs ["body_search" ] = body_search
574
-
575
- hits = await self .table .aann_search (
576
- vector = embedding ,
577
- n = k ,
578
- ** kwargs ,
579
- )
580
- return [
581
- (
582
- self ._row_to_document (row = hit ),
583
- hit ["vector" ],
584
- hit ["row_id" ],
585
- )
586
- for hit in hits
587
- ]
588
-
589
- @staticmethod
590
- def _row_to_document (row : Dict [str , Any ]) -> Document :
591
- return Document (
592
- id = row ["row_id" ],
593
- page_content = row ["body_blob" ],
594
- metadata = row ["metadata" ],
595
- )
596
-
597
503
def get_by_document_id (self , document_id : str ) -> Document | None :
598
504
"""Retrieve a single document from the store, given its document ID.
599
505
@@ -624,7 +530,7 @@ async def aget_by_document_id(self, document_id: str) -> Document | None:
624
530
625
531
def metadata_search (
626
532
self ,
627
- filter : Optional [ Dict [ str , str ]] = None ,
533
+ filter : dict [ str , Any ] = {}, # noqa: B006
628
534
n : int = 5 ,
629
535
) -> Iterable [Document ]:
630
536
"""Get documents via a metadata search.
@@ -638,7 +544,7 @@ def metadata_search(
638
544
639
545
async def ametadata_search (
640
546
self ,
641
- filter : Optional [ Dict [ str , str ]] = None ,
547
+ filter : dict [ str , Any ] = {}, # noqa: B006
642
548
n : int = 5 ,
643
549
) -> Iterable [Document ]:
644
550
"""Get documents via a metadata search.
@@ -681,11 +587,7 @@ async def asimilarity_search_with_embedding_id_by_vector(
681
587
)
682
588
return [
683
589
(
684
- Document (
685
- page_content = hit ["body_blob" ],
686
- metadata = hit ["metadata" ],
687
- id = hit ["row_id" ],
688
- ),
590
+ self ._row_to_document (row = hit ),
689
591
hit ["vector" ],
690
592
hit ["row_id" ],
691
593
)
0 commit comments