community[patch]: Fixing some caching issues for AzureCosmosDBSemanticCache (#18884)

Fixing some issues for AzureCosmosDBSemanticCache
- Added the entry for "AzureCosmosDBSemanticCache" which was missing in
langchain/cache.py
- Added application name when creating the MongoClient for the
AzureCosmosDBVectorSearch, for tracking purposes.

@baskaryan, can you please review this PR, we need this to go in asap.
These are just small fixes which we found today in our testing.
This commit is contained in:
Aayush Kataria
2024-03-25 19:06:17 -07:00
committed by GitHub
parent a6cbb755a7
commit 03c38005cb
6 changed files with 84 additions and 62 deletions

View File

@@ -1879,6 +1879,7 @@ class AzureCosmosDBSemanticCache(BaseCache):
ef_construction: int = 64,
ef_search: int = 40,
score_threshold: Optional[float] = None,
application_name: str = "LANGCHAIN_CACHING_PYTHON",
):
"""
Args:
@@ -1920,6 +1921,7 @@ class AzureCosmosDBSemanticCache(BaseCache):
(40 by default). A higher value provides better
recall at the cost of speed.
score_threshold: Maximum score used to filter the vector search documents.
application_name: Application name for the client for tracking and logging
"""
self._validate_enum_value(similarity, CosmosDBSimilarityType)
@@ -1942,6 +1944,7 @@ class AzureCosmosDBSemanticCache(BaseCache):
self.ef_search = ef_search
self.score_threshold = score_threshold
self._cache_dict: Dict[str, AzureCosmosDBVectorSearch] = {}
self.application_name = application_name
def _index_name(self, llm_string: str) -> str:
hashed_index = _hash(llm_string)
@@ -1972,6 +1975,7 @@ class AzureCosmosDBSemanticCache(BaseCache):
namespace=namespace,
embedding=self.embedding,
index_name=index_name,
application_name=self.application_name,
)
# create index for the vectorstore