Repository: langchain-ai/langchain-nvidia (language: python)

Issue:
Unable to create pickle file for NVIDIAEmbeddings
When using simple vectorstore like FAISS/Chroma, we prefer to store embeddings in pkl file. But when we're trying to store it in a pickle file it raise exception. 


```
    vectorstore = FAISS.from_documents(documents=splits, embedding=NVIDIAEmbeddings(model="ai-embed-qa-4"))

    # Save the vectorstore to a file for qna
    with open(vectorstore_path, "wb") as handle:
        pickle.dump(vectorstore, handle, protocol=pickle.HIGHEST_PROTOCOL)

```

```
    pickle.dump(vectorstore, handle, protocol=pickle.HIGHEST_PROTOCOL)
_pickle.PicklingError: Can't pickle <function NVEModel.<lambda> at 0x7fa3e43915a0>: attribute lookup NVEModel.<lambda> on langchain_nvidia_ai_endpoints._common failed```



Discussion / hints:

Fix patch:
diff --git a/libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py b/libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py
index 028ce03a..336eadd0 100644
--- a/libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py
+++ b/libs/ai-endpoints/langchain_nvidia_ai_endpoints/_common.py
@@ -39,6 +39,10 @@
 _MODE_TYPE = Literal["catalog", "nvidia", "nim", "open", "openai"]
 
 
+def default_payload_fn(payload: dict) -> dict:
+    return payload
+
+
 class NVEModel(BaseModel):
 
     """
@@ -80,7 +84,9 @@ class Config:
     last_response: Response = Field(
         None, description="Last response sent from the server"
     )
-    payload_fn: Callable = Field(lambda d: d, description="Function to process payload")
+    payload_fn: Callable = Field(
+        default_payload_fn, description="Function to process payload"
+    )
     headers_tmpl: dict = Field(
         ...,
         description="Headers template for API calls."


Test patch:
diff --git a/libs/ai-endpoints/tests/unit_tests/test_serialization.py b/libs/ai-endpoints/tests/unit_tests/test_serialization.py
index d0f77f7b..34f3100e 100644
--- a/libs/ai-endpoints/tests/unit_tests/test_serialization.py
+++ b/libs/ai-endpoints/tests/unit_tests/test_serialization.py
@@ -1,7 +1,9 @@
+import pickle
+
 from langchain_core.load.dump import dumps
 from langchain_core.load.load import loads
 
-from langchain_nvidia_ai_endpoints import ChatNVIDIA
+from langchain_nvidia_ai_endpoints import ChatNVIDIA, NVIDIAEmbeddings
 
 
 def test_serialize_chatnvidia() -> None:
@@ -14,3 +16,11 @@ def test_serialize_chatnvidia() -> None:
     )
     assert x == y
     assert isinstance(y, ChatNVIDIA)
+
+
+def test_pickle_embeddings() -> None:
+    x = NVIDIAEmbeddings()
+    y = pickle.loads(pickle.dumps(x))
+    assert x.model == y.model
+    assert x.max_batch_size == y.max_batch_size
+    assert isinstance(y, NVIDIAEmbeddings)