mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-06 21:43:44 +00:00
Handled empty search result handling and updated the notebook (#27914)
- [ ] **PR title**: "community: updated Kinetica vectorstore" - **Description:** Handled empty search results - **Issue:** used to throw error if the search results were empty @efriis
This commit is contained in:
@@ -93,7 +93,7 @@ class Kinetica(VectorStore):
|
||||
To use, you should have the ``gpudb`` python package installed.
|
||||
|
||||
Args:
|
||||
kinetica_settings: Kinetica connection settings class.
|
||||
config: Kinetica connection settings class.
|
||||
embedding_function: Any embedding function implementing
|
||||
`langchain.embeddings.base.Embeddings` interface.
|
||||
collection_name: The name of the collection to use. (default: langchain)
|
||||
@@ -170,7 +170,7 @@ class Kinetica(VectorStore):
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import Kinetica python API. "
|
||||
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||
"Please install it with `pip install gpudb>=7.2.2.0`."
|
||||
)
|
||||
|
||||
self.dimensions = dimensions
|
||||
@@ -199,7 +199,7 @@ class Kinetica(VectorStore):
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import Kinetica python API. "
|
||||
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||
"Please install it with `pip install gpudb>=7.2.2.0`."
|
||||
)
|
||||
|
||||
options = GPUdb.Options()
|
||||
@@ -290,7 +290,7 @@ class Kinetica(VectorStore):
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import Kinetica python API. "
|
||||
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||
"Please install it with `pip install gpudb>=7.2.2.0`."
|
||||
)
|
||||
return GPUdbTable(
|
||||
_type=self.table_schema,
|
||||
@@ -428,7 +428,7 @@ class Kinetica(VectorStore):
|
||||
k: int = 4,
|
||||
filter: Optional[dict] = None,
|
||||
) -> List[Tuple[Document, float]]:
|
||||
from gpudb import GPUdbException
|
||||
# from gpudb import GPUdbException
|
||||
|
||||
resp: Dict = self.__query_collection(embedding, k, filter)
|
||||
if resp and resp["status_info"]["status"] == "OK" and "records" in resp:
|
||||
@@ -436,9 +436,10 @@ class Kinetica(VectorStore):
|
||||
results = list(zip(*list(records.values())))
|
||||
|
||||
return self._results_to_docs_and_scores(results)
|
||||
else:
|
||||
self.logger.error(resp["status_info"]["message"])
|
||||
raise GPUdbException(resp["status_info"]["message"])
|
||||
|
||||
self.logger.error(resp["status_info"]["message"])
|
||||
# raise GPUdbException(resp["status_info"]["message"])
|
||||
return []
|
||||
|
||||
def similarity_search_by_vector(
|
||||
self,
|
||||
@@ -464,16 +465,20 @@ class Kinetica(VectorStore):
|
||||
|
||||
def _results_to_docs_and_scores(self, results: Any) -> List[Tuple[Document, float]]:
|
||||
"""Return docs and scores from results."""
|
||||
docs = [
|
||||
(
|
||||
Document(
|
||||
page_content=result[0],
|
||||
metadata=json.loads(result[1]),
|
||||
),
|
||||
result[2] if self.embedding_function is not None else None,
|
||||
)
|
||||
for result in results
|
||||
]
|
||||
docs = (
|
||||
[
|
||||
(
|
||||
Document(
|
||||
page_content=result[0],
|
||||
metadata=json.loads(result[1]),
|
||||
),
|
||||
result[2] if self.embedding_function is not None else None,
|
||||
)
|
||||
for result in results
|
||||
]
|
||||
if len(results) > 0
|
||||
else []
|
||||
)
|
||||
return docs
|
||||
|
||||
def _select_relevance_score_fn(self) -> Callable[[float], float]:
|
||||
|
Reference in New Issue
Block a user