Skip to content

Commit

Permalink
langchain-mongodb: [test-fix] add explicit index_name setting on test…
Browse files Browse the repository at this point in the history
… vector creation (#19245)

- **Description:** Tests fail to do value lookup because it does not
specify the index name
  - **Issue:** the issue # Failing integration test
 

- [x] **Add tests and docs**: Tests now pass


- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/
  • Loading branch information
Jibola authored Mar 18, 2024
1 parent 94e58dd commit 516cc44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libs/partners/mongodb/langchain_mongodb/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def __init__(
embedding: Embeddings,
collection_name: str = "default",
database_name: str = "default",
index_name: str = "default",
wait_until_ready: bool = False,
**kwargs: Dict[str, Any],
):
Expand All @@ -229,13 +230,20 @@ def __init__(
Defaults to "default".
database_name (str): MongoDB Database where to store texts.
Defaults to "default".
index_name: Name of the Atlas Search index.
defaults to 'default'
wait_until_ready (bool): Block until MongoDB Atlas finishes indexing
the stored text. Hard timeout of 10 seconds. Defaults to False.
"""
client = _generate_mongo_client(connection_string)
self.collection = client[database_name][collection_name]
self._wait_until_ready = wait_until_ready
super().__init__(self.collection, embedding, **kwargs) # type: ignore
super().__init__(
collection=self.collection,
embedding=embedding,
index_name=index_name,
**kwargs, # type: ignore
)

def lookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
"""Look up based on prompt and llm_string."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def llm_cache(cls: Any) -> BaseCache:
connection_string=CONN_STRING,
collection_name=COLLECTION,
database_name=DATABASE,
index_name=INDEX_NAME,
wait_until_ready=True,
)
)
Expand Down

0 comments on commit 516cc44

Please sign in to comment.