The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Replace loop appends with list comprehension. (#5528)
Taras Tsugrii0ad76c338005
diff --git a/langchain/retrievers/tfidf.py b/langchain/retrievers/tfidf.pyindex 3ccece7d79..db14f61e27 100644--- a/langchain/retrievers/tfidf.py+++ b/langchain/retrievers/tfidf.py@@ -67,9 +67,7 @@ class TFIDFRetriever(BaseRetriever, BaseModel):results = cosine_similarity(self.tfidf_array, query_vec).reshape((-1,)) # Op -- (n_docs,1) -- Cosine Sim with each doc- return_docs = []- for i in results.argsort()[-self.k :][::-1]:- return_docs.append(self.docs[i])+ return_docs = [self.docs[i] for i in results.argsort()[-self.k :][::-1]]return return_docsasync def aget_relevant_documents(self, query: str) -> List[Document]: