DSPy: The framework for programming—not prompting—language models
Python
fix(dspy): updating syntax for embeddings method call which will be deprecated
alejandroa048a511f8e9
diff --git a/docs/api/retrieval_model_clients/SnowflakeRM.md b/docs/api/retrieval_model_clients/SnowflakeRM.mdindex 7b7a3ee5c..78695dc0c 100644--- a/docs/api/retrieval_model_clients/SnowflakeRM.md+++ b/docs/api/retrieval_model_clients/SnowflakeRM.md@@ -1,5 +1,5 @@----sidebar_position:+sidebar_position:---# retrieve.SnowflakeRM@@ -20,6 +20,7 @@ SnowflakeRM(```**Parameters:**+- `snowflake_table_name (str)`: The name of the Snowflake table containing embeddings.- `snowflake_credentials (dict)`: The connection parameters needed to initialize a Snowflake Snowpark Session.- `k (int, optional)`: The number of top passages to retrieve. Defaults to 3.@@ -34,10 +35,12 @@ SnowflakeRM(Search the Snowflake table for the top `k` passages matching the given query or queries, using embeddings generated via the default `e5-base-v2` model or the specified `embedding_model`.**Parameters:**+- `query_or_queries` (_Union[str, List[str]]_): The query or list of queries to search for.- `k` (_Optional[int]_, _optional_): The number of results to retrieve. If not specified, defaults to the value set during initialization.**Returns:**+- `dspy.Prediction`: Contains the retrieved passages, each represented as a `dotdict` with schema `[{"id": str, "score": float, "long_text": str, "metadatas": dict }]`### Quickstart@@ -53,14 +56,14 @@ from dspy.retrieve.snowflake_rm import SnowflakeRMimport osconnection_parameters = {-+"account": os.getenv('SNOWFLAKE_ACCOUNT'),"user": os.getenv('SNOWFLAKE_USER'),"password": os.getenv('SNOWFLAKE_PASSWORD'),"role": os.getenv('SNOWFLAKE_ROLE'),"warehouse": os.getenv('SNOWFLAKE_WAREHOUSE'),"database": os.getenv('SNOWFLAKE_DATABASE'),- "schema": os.getenv('SNOWFLAKE_SCHEMA')}+ "schema": os.getenv('SNOWFLAKE_SCHEMA')}retriever_model = SnowflakeRM(snowflake_table_name="<YOUR_SNOWFLAKE_TABLE_NAME>",@@ -74,4 +77,3 @@ results = retriever_model("Explore the meaning of life", k=5)for result in results:print("Document:", result.long_text, "\n")```-diff --git a/dspy/retrieve/snowflake_rm.py b/dspy/retrieve/snowflake_rm.pyindex 52a73bd6f..ec7dc389a 100644--- a/dspy/retrieve/snowflake_rm.py+++ b/dspy/retrieve/snowflake_rm.py@@ -11,7 +11,7 @@ try:except ImportError:raise ImportError(- "The snowflake-snowpark-python library is required to use SnowflakeRM. Install it with dspy-ai[snowflake]"+ "The snowflake-snowpark-python library is required to use SnowflakeRM. Install it with dspy-ai[snowflake]",)@@ -93,7 +93,7 @@ class SnowflakeRM(dspy.Retrieve):lit(query_embeddings).cast(VectorType(float, len(query_embeddings))),).as_("dist"),)- .sort("dist",ascending=False)+ .sort("dist", ascending=False).limit(k))@@ -101,15 +101,14 @@ class SnowflakeRM(dspy.Retrieve):@classmethoddef _init_cortex(cls, credentials: dict) -> None:-session = Session.builder.configs(credentials).create()- session.query_tag = {"origin":"sf_sit", "name":"dspy", "version":{"major":1, "minor":0}}+ session.query_tag = {"origin": "sf_sit", "name": "dspy", "version": {"major": 1, "minor": 0}}return sessiondef _get_embeddings(self, query: str) -> list[float]:# create embeddings for the query- embed = snow_fn.builtin("snowflake.cortex.embed_text")+ embed = snow_fn.builtin("snowflake.cortex.embed_text_768")cortex_embed_args = embed(snow_fn.lit(self.embeddings_model), snow_fn.lit(query))return self.client.range(1).withColumn("complete_cal", cortex_embed_args).collect()[0].COMPLETE_CAL