mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-19 11:08:55 +00:00
community[patch]: Kinetica Integrations handled error in querying; quotes in table names; updated gpudb API (#22724)
- [ ] **Miscellaneous updates and fixes**: - **Description:** Handled error in querying; quotes in table names; updated gpudb API - **Issue:** Threw an error with an error message difficult to understand if a query failed or returned no records - **Dependencies:** Updated GPUDB API version to `7.2.0.9` @baskaryan @hwchase17
This commit is contained in:
parent
27b9ea14a5
commit
ad101adec8
@ -15,7 +15,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%pip install gpudb==7.2.0.1"
|
"%pip install gpudb==7.2.0.9"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -97,14 +97,14 @@
|
|||||||
"# data and the `SCHEMA.TABLE` combination must exist in Kinetica.\n",
|
"# data and the `SCHEMA.TABLE` combination must exist in Kinetica.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"QUERY = \"select text, survey_id as source from SCHEMA.TABLE limit 10\"\n",
|
"QUERY = \"select text, survey_id as source from SCHEMA.TABLE limit 10\"\n",
|
||||||
"snowflake_loader = KineticaLoader(\n",
|
"kl = KineticaLoader(\n",
|
||||||
" query=QUERY,\n",
|
" query=QUERY,\n",
|
||||||
" host=HOST,\n",
|
" host=HOST,\n",
|
||||||
" username=USERNAME,\n",
|
" username=USERNAME,\n",
|
||||||
" password=PASSWORD,\n",
|
" password=PASSWORD,\n",
|
||||||
" metadata_columns=[\"source\"],\n",
|
" metadata_columns=[\"source\"],\n",
|
||||||
")\n",
|
")\n",
|
||||||
"kinetica_documents = snowflake_loader.load()\n",
|
"kinetica_documents = kl.load()\n",
|
||||||
"print(kinetica_documents)"
|
"print(kinetica_documents)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Please ensure that this connector is installed in your working environment.\n",
|
"# Please ensure that this connector is installed in your working environment.\n",
|
||||||
"%pip install gpudb==7.2.0.1"
|
"%pip install gpudb==7.2.0.9"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# Pip install necessary package\n",
|
"# Pip install necessary package\n",
|
||||||
"%pip install --upgrade --quiet langchain-openai langchain-community\n",
|
"%pip install --upgrade --quiet langchain-openai langchain-community\n",
|
||||||
"%pip install gpudb==7.2.0.1\n",
|
"%pip install gpudb==7.2.0.9\n",
|
||||||
"%pip install --upgrade --quiet tiktoken"
|
"%pip install --upgrade --quiet tiktoken"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -49,7 +49,7 @@ class KineticaLoader(BaseLoader):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import Kinetica python API. "
|
"Could not import Kinetica python API. "
|
||||||
"Please install it with `pip install gpudb==7.2.0.1`."
|
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -168,7 +168,7 @@ class Kinetica(VectorStore):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import Kinetica python API. "
|
"Could not import Kinetica python API. "
|
||||||
"Please install it with `pip install gpudb==7.2.0.1`."
|
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.dimensions = dimensions
|
self.dimensions = dimensions
|
||||||
@ -197,7 +197,7 @@ class Kinetica(VectorStore):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import Kinetica python API. "
|
"Could not import Kinetica python API. "
|
||||||
"Please install it with `pip install gpudb==7.2.0.1`."
|
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||||
)
|
)
|
||||||
|
|
||||||
options = GPUdb.Options()
|
options = GPUdb.Options()
|
||||||
@ -224,6 +224,8 @@ class Kinetica(VectorStore):
|
|||||||
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
||||||
pre_delete_collection: bool = False,
|
pre_delete_collection: bool = False,
|
||||||
logger: Optional[logging.Logger] = None,
|
logger: Optional[logging.Logger] = None,
|
||||||
|
*,
|
||||||
|
schema_name: str = _LANGCHAIN_DEFAULT_SCHEMA_NAME,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Kinetica:
|
) -> Kinetica:
|
||||||
"""Class method to assist in constructing the `Kinetica` store instance
|
"""Class method to assist in constructing the `Kinetica` store instance
|
||||||
@ -239,8 +241,10 @@ class Kinetica(VectorStore):
|
|||||||
with each text. Defaults to None.
|
with each text. Defaults to None.
|
||||||
ids (Optional[List[str]], optional): List of unique IDs (UUID by default)
|
ids (Optional[List[str]], optional): List of unique IDs (UUID by default)
|
||||||
associated with each text. Defaults to None.
|
associated with each text. Defaults to None.
|
||||||
collection_name (str, optional): Kinetica schema name.
|
collection_name (str, optional): Kinetica table name.
|
||||||
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
||||||
|
schema_name (str, optional): Kinetica schema name.
|
||||||
|
Defaults to _LANGCHAIN_DEFAULT_SCHEMA_NAME.
|
||||||
distance_strategy (DistanceStrategy, optional): Not used for now.
|
distance_strategy (DistanceStrategy, optional): Not used for now.
|
||||||
Defaults to DEFAULT_DISTANCE_STRATEGY.
|
Defaults to DEFAULT_DISTANCE_STRATEGY.
|
||||||
pre_delete_collection (bool, optional): Whether to delete the Kinetica
|
pre_delete_collection (bool, optional): Whether to delete the Kinetica
|
||||||
@ -260,8 +264,8 @@ class Kinetica(VectorStore):
|
|||||||
store = cls(
|
store = cls(
|
||||||
config=config,
|
config=config,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
|
schema_name=schema_name,
|
||||||
embedding_function=embedding,
|
embedding_function=embedding,
|
||||||
# dimensions=dimensions,
|
|
||||||
distance_strategy=distance_strategy,
|
distance_strategy=distance_strategy,
|
||||||
pre_delete_collection=pre_delete_collection,
|
pre_delete_collection=pre_delete_collection,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
@ -284,7 +288,7 @@ class Kinetica(VectorStore):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import Kinetica python API. "
|
"Could not import Kinetica python API. "
|
||||||
"Please install it with `pip install gpudb==7.2.0.1`."
|
"Please install it with `pip install gpudb==7.2.0.9`."
|
||||||
)
|
)
|
||||||
return GPUdbTable(
|
return GPUdbTable(
|
||||||
_type=self.table_schema,
|
_type=self.table_schema,
|
||||||
@ -422,12 +426,17 @@ class Kinetica(VectorStore):
|
|||||||
k: int = 4,
|
k: int = 4,
|
||||||
filter: Optional[dict] = None,
|
filter: Optional[dict] = None,
|
||||||
) -> List[Tuple[Document, float]]:
|
) -> List[Tuple[Document, float]]:
|
||||||
|
from gpudb import GPUdbException
|
||||||
|
|
||||||
resp: Dict = self.__query_collection(embedding, k, filter)
|
resp: Dict = self.__query_collection(embedding, k, filter)
|
||||||
|
if resp and resp["status_info"]["status"] == "OK" and "records" in resp:
|
||||||
|
records: OrderedDict = resp["records"]
|
||||||
|
results = list(zip(*list(records.values())))
|
||||||
|
|
||||||
records: OrderedDict = resp["records"]
|
return self._results_to_docs_and_scores(results)
|
||||||
results = list(zip(*list(records.values())))
|
else:
|
||||||
|
self.logger.error(resp["status_info"]["message"])
|
||||||
return self._results_to_docs_and_scores(results)
|
raise GPUdbException(resp["status_info"]["message"])
|
||||||
|
|
||||||
def similarity_search_by_vector(
|
def similarity_search_by_vector(
|
||||||
self,
|
self,
|
||||||
@ -545,7 +554,7 @@ class Kinetica(VectorStore):
|
|||||||
query_string = f"""
|
query_string = f"""
|
||||||
SELECT text, metadata, {dist_strategy}(embedding, '{embedding_str}')
|
SELECT text, metadata, {dist_strategy}(embedding, '{embedding_str}')
|
||||||
as distance, embedding
|
as distance, embedding
|
||||||
FROM {self.table_name}
|
FROM "{self.schema_name}"."{self.collection_name}"
|
||||||
{where_clause}
|
{where_clause}
|
||||||
ORDER BY distance asc NULLS LAST
|
ORDER BY distance asc NULLS LAST
|
||||||
LIMIT {k}
|
LIMIT {k}
|
||||||
@ -760,6 +769,8 @@ class Kinetica(VectorStore):
|
|||||||
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
||||||
ids: Optional[List[str]] = None,
|
ids: Optional[List[str]] = None,
|
||||||
pre_delete_collection: bool = False,
|
pre_delete_collection: bool = False,
|
||||||
|
*,
|
||||||
|
schema_name: str = _LANGCHAIN_DEFAULT_SCHEMA_NAME,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Kinetica:
|
) -> Kinetica:
|
||||||
"""Adds the texts passed in to the vector store and returns it
|
"""Adds the texts passed in to the vector store and returns it
|
||||||
@ -773,6 +784,8 @@ class Kinetica(VectorStore):
|
|||||||
config (KineticaSettings): a `KineticaSettings` instance
|
config (KineticaSettings): a `KineticaSettings` instance
|
||||||
collection_name (str, optional): Kinetica schema name.
|
collection_name (str, optional): Kinetica schema name.
|
||||||
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
||||||
|
schema_name (str, optional): Kinetica schema name.
|
||||||
|
Defaults to _LANGCHAIN_DEFAULT_SCHEMA_NAME.
|
||||||
distance_strategy (DistanceStrategy, optional): Distance strategy
|
distance_strategy (DistanceStrategy, optional): Distance strategy
|
||||||
e.g., l2, cosine etc.. Defaults to DEFAULT_DISTANCE_STRATEGY.
|
e.g., l2, cosine etc.. Defaults to DEFAULT_DISTANCE_STRATEGY.
|
||||||
ids (Optional[List[str]], optional): A list of UUIDs for each
|
ids (Optional[List[str]], optional): A list of UUIDs for each
|
||||||
@ -804,6 +817,7 @@ class Kinetica(VectorStore):
|
|||||||
metadatas=metadatas,
|
metadatas=metadatas,
|
||||||
ids=ids,
|
ids=ids,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
|
schema_name=schema_name,
|
||||||
distance_strategy=distance_strategy,
|
distance_strategy=distance_strategy,
|
||||||
pre_delete_collection=pre_delete_collection,
|
pre_delete_collection=pre_delete_collection,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
@ -823,6 +837,8 @@ class Kinetica(VectorStore):
|
|||||||
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
||||||
ids: Optional[List[str]] = None,
|
ids: Optional[List[str]] = None,
|
||||||
pre_delete_collection: bool = False,
|
pre_delete_collection: bool = False,
|
||||||
|
*,
|
||||||
|
schema_name: str = _LANGCHAIN_DEFAULT_SCHEMA_NAME,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Kinetica:
|
) -> Kinetica:
|
||||||
"""Adds the embeddings passed in to the vector store and returns it
|
"""Adds the embeddings passed in to the vector store and returns it
|
||||||
@ -839,6 +855,8 @@ class Kinetica(VectorStore):
|
|||||||
default will be used. Defaults to Dimension.OPENAI.
|
default will be used. Defaults to Dimension.OPENAI.
|
||||||
collection_name (str, optional): Kinetica schema name.
|
collection_name (str, optional): Kinetica schema name.
|
||||||
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
||||||
|
schema_name (str, optional): Kinetica schema name.
|
||||||
|
Defaults to _LANGCHAIN_DEFAULT_SCHEMA_NAME.
|
||||||
distance_strategy (DistanceStrategy, optional): Distance strategy
|
distance_strategy (DistanceStrategy, optional): Distance strategy
|
||||||
e.g., l2, cosine etc.. Defaults to DEFAULT_DISTANCE_STRATEGY.
|
e.g., l2, cosine etc.. Defaults to DEFAULT_DISTANCE_STRATEGY.
|
||||||
ids (Optional[List[str]], optional): A list of UUIDs for each text/document.
|
ids (Optional[List[str]], optional): A list of UUIDs for each text/document.
|
||||||
@ -863,6 +881,7 @@ class Kinetica(VectorStore):
|
|||||||
metadatas=metadatas,
|
metadatas=metadatas,
|
||||||
ids=ids,
|
ids=ids,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
|
schema_name=schema_name,
|
||||||
distance_strategy=distance_strategy,
|
distance_strategy=distance_strategy,
|
||||||
pre_delete_collection=pre_delete_collection,
|
pre_delete_collection=pre_delete_collection,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
@ -879,6 +898,8 @@ class Kinetica(VectorStore):
|
|||||||
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
||||||
ids: Optional[List[str]] = None,
|
ids: Optional[List[str]] = None,
|
||||||
pre_delete_collection: bool = False,
|
pre_delete_collection: bool = False,
|
||||||
|
*,
|
||||||
|
schema_name: str = _LANGCHAIN_DEFAULT_SCHEMA_NAME,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Kinetica:
|
) -> Kinetica:
|
||||||
"""Adds the list of `Document` passed in to the vector store and returns it
|
"""Adds the list of `Document` passed in to the vector store and returns it
|
||||||
@ -892,6 +913,8 @@ class Kinetica(VectorStore):
|
|||||||
the texts/documents. Defaults to None.
|
the texts/documents. Defaults to None.
|
||||||
collection_name (str, optional): Kinetica schema name.
|
collection_name (str, optional): Kinetica schema name.
|
||||||
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
Defaults to _LANGCHAIN_DEFAULT_COLLECTION_NAME.
|
||||||
|
schema_name (str, optional): Kinetica schema name.
|
||||||
|
Defaults to _LANGCHAIN_DEFAULT_SCHEMA_NAME.
|
||||||
distance_strategy (DistanceStrategy, optional): Distance strategy
|
distance_strategy (DistanceStrategy, optional): Distance strategy
|
||||||
e.g., l2, cosine etc.. Defaults to DEFAULT_DISTANCE_STRATEGY.
|
e.g., l2, cosine etc.. Defaults to DEFAULT_DISTANCE_STRATEGY.
|
||||||
ids (Optional[List[str]], optional): A list of UUIDs for each text/document.
|
ids (Optional[List[str]], optional): A list of UUIDs for each text/document.
|
||||||
@ -912,6 +935,7 @@ class Kinetica(VectorStore):
|
|||||||
metadatas=metadatas,
|
metadatas=metadatas,
|
||||||
config=config,
|
config=config,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
|
schema_name=schema_name,
|
||||||
distance_strategy=distance_strategy,
|
distance_strategy=distance_strategy,
|
||||||
ids=ids,
|
ids=ids,
|
||||||
pre_delete_collection=pre_delete_collection,
|
pre_delete_collection=pre_delete_collection,
|
||||||
|
@ -46,7 +46,8 @@ def test_kinetica(create_config: KineticaSettings) -> None:
|
|||||||
texts=texts,
|
texts=texts,
|
||||||
metadatas=metadatas,
|
metadatas=metadatas,
|
||||||
embedding=FakeEmbeddingsWithAdaDimension(),
|
embedding=FakeEmbeddingsWithAdaDimension(),
|
||||||
collection_name="test_kinetica",
|
collection_name="1test_kinetica",
|
||||||
|
schema_name="1test",
|
||||||
pre_delete_collection=True,
|
pre_delete_collection=True,
|
||||||
)
|
)
|
||||||
output = docsearch.similarity_search("foo", k=1)
|
output = docsearch.similarity_search("foo", k=1)
|
||||||
|
Loading…
Reference in New Issue
Block a user