feature: added warning when duckdb is used as a vectorstore without pandas (#30435)

added warning when duckdb is used as a vectorstore without pandas being
installed (currently used for similarity search result processing)

Thank you for contributing to LangChain!

- [ ] **PR title**: "community: added warning when duckdb is used as a
vectorstore without pandas"


- [ ] **PR message**: ***Delete this entire checklist*** and replace
with
- **Description:** displays a warning when using duckdb as a vector
store without pandas being installed, as it is used by the
`similarity_search` function
    - **Issue:** #29933 
    - **Dependencies:** None

---------

Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
Dhruvajyoti Sarma
2025-03-23 00:57:21 +05:30
committed by GitHub
parent e81b82ee0b
commit 31551dab40

View File

@@ -99,6 +99,7 @@ class DuckDB(VectorStore):
"Could not import duckdb package. "
"Please install it with `pip install duckdb`."
)
self.duckdb = duckdb
self._embedding = embedding
self._vector_key = vector_key
@@ -209,6 +210,11 @@ class DuckDB(VectorStore):
Returns:
A list of Documents most similar to the query.
"""
try:
import pandas as pandas
except ImportError:
warnings.warn("You may need to `pip install pandas` to use this method.")
embedding = self._embedding.embed_query(query) # type: ignore
list_cosine_similarity = self.duckdb.FunctionExpression(
"list_cosine_similarity",