Skip to content

Commit 5ea2c44

Browse files
committed
lint
1 parent 94ba11b commit 5ea2c44

File tree

4 files changed

+9
-107
lines changed

4 files changed

+9
-107
lines changed

libs/community/langchain_community/graph_vectorstores/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,5 @@
152152
"Node",
153153
"Link",
154154
"CassandraGraphVectorStore",
155-
"MmrHelper"
155+
"MmrHelper",
156156
]

libs/community/langchain_community/graph_vectorstores/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ async def asearch(
632632
elif search_type == "traversal":
633633
return [doc async for doc in self.atraversal_search(query, **kwargs)]
634634
elif search_type == "mmr_traversal":
635-
return list(self.ammr_traversal_search(query, **kwargs))
635+
return [doc async for doc in self.ammr_traversal_search(query, **kwargs)]
636636
else:
637637
raise ValueError(
638638
f"search_type of {search_type} not allowed. Expected "

libs/community/langchain_community/graph_vectorstores/cassandra.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def metadata_search(
447447
return [
448448
self._restore_links(doc)
449449
for doc in self.vector_store.metadata_search(
450-
filter=filter,
450+
filter=filter or {},
451451
n=n,
452452
)
453453
]
@@ -466,7 +466,7 @@ async def ametadata_search(
466466
return [
467467
self._restore_links(doc)
468468
for doc in await self.vector_store.ametadata_search(
469-
filter=filter,
469+
filter=filter or {},
470470
n=n,
471471
)
472472
]
@@ -594,7 +594,7 @@ async def fetch_initial_candidates() -> None:
594594
retrieved_docs[doc_id] = doc
595595

596596
if doc_id not in outgoing_links_map:
597-
node = self._doc_to_node(doc)
597+
node = _doc_to_node(doc)
598598
outgoing_links_map[doc_id] = _outgoing_links(node=node)
599599
candidates[doc_id] = embedding
600600
helper.add_candidates(candidates)
@@ -952,7 +952,7 @@ async def _get_outgoing_links(self, source_ids: Iterable[str]) -> set[Link]:
952952

953953
for doc in docs:
954954
if doc is not None:
955-
node = self._doc_to_node(doc=doc)
955+
node = _doc_to_node(doc=doc)
956956
links.update(_outgoing_links(node=node))
957957

958958
return links

libs/community/langchain_community/vectorstores/cassandra.py

+3-101
Original file line numberDiff line numberDiff line change
@@ -500,100 +500,6 @@ def _row_to_document(row: Dict[str, Any]) -> Document:
500500
metadata=row["metadata"],
501501
)
502502

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-
597503
def get_by_document_id(self, document_id: str) -> Document | None:
598504
"""Retrieve a single document from the store, given its document ID.
599505
@@ -624,7 +530,7 @@ async def aget_by_document_id(self, document_id: str) -> Document | None:
624530

625531
def metadata_search(
626532
self,
627-
filter: Optional[Dict[str, str]] = None,
533+
filter: dict[str, Any] = {}, # noqa: B006
628534
n: int = 5,
629535
) -> Iterable[Document]:
630536
"""Get documents via a metadata search.
@@ -638,7 +544,7 @@ def metadata_search(
638544

639545
async def ametadata_search(
640546
self,
641-
filter: Optional[Dict[str, str]] = None,
547+
filter: dict[str, Any] = {}, # noqa: B006
642548
n: int = 5,
643549
) -> Iterable[Document]:
644550
"""Get documents via a metadata search.
@@ -681,11 +587,7 @@ async def asimilarity_search_with_embedding_id_by_vector(
681587
)
682588
return [
683589
(
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),
689591
hit["vector"],
690592
hit["row_id"],
691593
)

0 commit comments

Comments
 (0)