mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-09 02:33:34 +00:00
Compare commits
4 Commits
langchain-
...
isaac/resp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d37fea552 | ||
|
|
2ac264ef82 | ||
|
|
c93f6a2146 | ||
|
|
56894b74c6 |
4
.github/scripts/check_diff.py
vendored
4
.github/scripts/check_diff.py
vendored
@@ -23,6 +23,9 @@ IGNORED_PARTNERS = [
|
||||
# specifically in huggingface jobs
|
||||
# https://github.com/langchain-ai/langchain/issues/25558
|
||||
"huggingface",
|
||||
# remove ai21 because of breaking changes in sdk version 2.14.0
|
||||
# that have not been fixed yet
|
||||
"ai21",
|
||||
]
|
||||
|
||||
|
||||
@@ -195,6 +198,7 @@ if __name__ == "__main__":
|
||||
dirs_to_run["test"].add("libs/partners/mistralai")
|
||||
dirs_to_run["test"].add("libs/partners/openai")
|
||||
dirs_to_run["test"].add("libs/partners/anthropic")
|
||||
dirs_to_run["test"].add("libs/partners/ai21")
|
||||
dirs_to_run["test"].add("libs/partners/fireworks")
|
||||
dirs_to_run["test"].add("libs/partners/groq")
|
||||
|
||||
|
||||
1
.github/workflows/_integration_test.yml
vendored
1
.github/workflows/_integration_test.yml
vendored
@@ -67,7 +67,6 @@ jobs:
|
||||
NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }}
|
||||
GOOGLE_SEARCH_API_KEY: ${{ secrets.GOOGLE_SEARCH_API_KEY }}
|
||||
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
|
||||
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
|
||||
EXA_API_KEY: ${{ secrets.EXA_API_KEY }}
|
||||
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
|
||||
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
|
||||
|
||||
1
.github/workflows/_release.yml
vendored
1
.github/workflows/_release.yml
vendored
@@ -273,7 +273,6 @@ jobs:
|
||||
GOOGLE_SEARCH_API_KEY: ${{ secrets.GOOGLE_SEARCH_API_KEY }}
|
||||
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
|
||||
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
|
||||
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
|
||||
EXA_API_KEY: ${{ secrets.EXA_API_KEY }}
|
||||
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
|
||||
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
|
||||
|
||||
3
.github/workflows/scheduled_test.yml
vendored
3
.github/workflows/scheduled_test.yml
vendored
@@ -25,6 +25,7 @@ jobs:
|
||||
- "libs/partners/fireworks"
|
||||
- "libs/partners/groq"
|
||||
- "libs/partners/mistralai"
|
||||
- "libs/partners/together"
|
||||
- "libs/partners/google-vertexai"
|
||||
- "libs/partners/google-genai"
|
||||
- "libs/partners/aws"
|
||||
@@ -90,8 +91,8 @@ jobs:
|
||||
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME }}
|
||||
FIREWORKS_API_KEY: ${{ secrets.FIREWORKS_API_KEY }}
|
||||
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
|
||||
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
|
||||
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
|
||||
TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }}
|
||||
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
|
||||
NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }}
|
||||
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
||||
|
||||
@@ -49,7 +49,7 @@ For these applications, LangChain simplifies the entire application lifecycle:
|
||||
- **`langchain-community`**: Third party integrations.
|
||||
- Some integrations have been further split into **partner packages** that only rely on **`langchain-core`**. Examples include **`langchain_openai`** and **`langchain_anthropic`**.
|
||||
- **`langchain`**: Chains, agents, and retrieval strategies that make up an application's cognitive architecture.
|
||||
- **[`LangGraph`](https://langchain-ai.github.io/langgraph/)**: A library for building robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph. Integrates smoothly with LangChain, but can be used without it. To learn more about LangGraph, check out our first LangChain Academy course, *Introduction to LangGraph*, available [here](https://academy.langchain.com/courses/intro-to-langgraph).
|
||||
- **[`LangGraph`](https://langchain-ai.github.io/langgraph/)**: A library for building robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph. Integrates smoothly with LangChain, but can be used without it.
|
||||
|
||||
### Productionization:
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ Example code for building applications with LangChain, with an emphasis on more
|
||||
|
||||
Notebook | Description
|
||||
:- | :-
|
||||
[agent_fireworks_ai_langchain_mongodb.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/agent_fireworks_ai_langchain_mongodb.ipynb) | Build an AI Agent With Memory Using MongoDB, LangChain and FireWorksAI.
|
||||
[mongodb-langchain-cache-memory.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/mongodb-langchain-cache-memory.ipynb) | Build a RAG Application with Semantic Cache Using MongoDB and LangChain.
|
||||
[LLaMA2_sql_chat.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/LLaMA2_sql_chat.ipynb) | Build a chat application that interacts with a SQL database using an open source llm (llama2), specifically demonstrated on an SQLite database containing rosters.
|
||||
[Semi_Structured_RAG.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/Semi_Structured_RAG.ipynb) | Perform retrieval-augmented generation (rag) on documents with semi-structured data, including text and tables, using unstructured for parsing, multi-vector retriever for storing, and lcel for implementing chains.
|
||||
[Semi_structured_and_multi_moda...](https://github.com/langchain-ai/langchain/tree/master/cookbook/Semi_structured_and_multi_modal_RAG.ipynb) | Perform retrieval-augmented generation (rag) on documents with semi-structured data and images, using unstructured for parsing, multi-vector retriever for storage and retrieval, and lcel for implementing chains.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -38,7 +38,7 @@
|
||||
"source": [
|
||||
"Connection is via `cassio` using `auto=True` parameter, and the notebook uses OpenAI. You should create a `.env` file accordingly.\n",
|
||||
"\n",
|
||||
"For Cassandra, set:\n",
|
||||
"For Casssandra, set:\n",
|
||||
"```bash\n",
|
||||
"CASSANDRA_CONTACT_POINTS\n",
|
||||
"CASSANDRA_USERNAME\n",
|
||||
|
||||
@@ -73,8 +73,6 @@ append-related:
|
||||
generate-references:
|
||||
$(PYTHON) scripts/generate_api_reference_links.py --docs_dir $(OUTPUT_NEW_DOCS_DIR)
|
||||
|
||||
update-md: generate-files md-sync
|
||||
|
||||
build: install-py-deps generate-files copy-infra render md-sync append-related
|
||||
|
||||
vercel-build: install-vercel-deps build generate-references
|
||||
|
||||
1457
docs/data/people.yml
1457
docs/data/people.yml
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,6 @@ From the opposite direction, scientists use `LangChain` in research and referenc
|
||||
|------------------|---------|-------------------|------------------------|
|
||||
| `2403.14403v2` [Adaptive-RAG: Learning to Adapt Retrieval-Augmented Large Language Models through Question Complexity](http://arxiv.org/abs/2403.14403v2) | Soyeong Jeong, Jinheon Baek, Sukmin Cho, et al. | 2024‑03‑21 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
| `2402.03620v1` [Self-Discover: Large Language Models Self-Compose Reasoning Structures](http://arxiv.org/abs/2402.03620v1) | Pei Zhou, Jay Pujara, Xiang Ren, et al. | 2024‑02‑06 | `Cookbook:` [Self-Discover](https://github.com/langchain-ai/langchain/blob/master/cookbook/self-discover.ipynb)
|
||||
| `2402.03367v2` [RAG-Fusion: a New Take on Retrieval-Augmented Generation](http://arxiv.org/abs/2402.03367v2) | Zackary Rackauckas | 2024‑01‑31 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
| `2401.18059v1` [RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval](http://arxiv.org/abs/2401.18059v1) | Parth Sarthi, Salman Abdullah, Aditi Tuli, et al. | 2024‑01‑31 | `Cookbook:` [Raptor](https://github.com/langchain-ai/langchain/blob/master/cookbook/RAPTOR.ipynb)
|
||||
| `2401.15884v2` [Corrective Retrieval Augmented Generation](http://arxiv.org/abs/2401.15884v2) | Shi-Qi Yan, Jia-Chen Gu, Yun Zhu, et al. | 2024‑01‑29 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), `Cookbook:` [Langgraph Crag](https://github.com/langchain-ai/langchain/blob/master/cookbook/langgraph_crag.ipynb)
|
||||
| `2401.08500v1` [Code Generation with AlphaCodium: From Prompt Engineering to Flow Engineering](http://arxiv.org/abs/2401.08500v1) | Tal Ridnik, Dedy Kredo, Itamar Friedman | 2024‑01‑16 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
@@ -23,7 +22,7 @@ From the opposite direction, scientists use `LangChain` in research and referenc
|
||||
| `2312.06648v2` [Dense X Retrieval: What Retrieval Granularity Should We Use?](http://arxiv.org/abs/2312.06648v2) | Tong Chen, Hongwei Wang, Sihao Chen, et al. | 2023‑12‑11 | `Template:` [propositional-retrieval](https://python.langchain.com/docs/templates/propositional-retrieval)
|
||||
| `2311.09210v1` [Chain-of-Note: Enhancing Robustness in Retrieval-Augmented Language Models](http://arxiv.org/abs/2311.09210v1) | Wenhao Yu, Hongming Zhang, Xiaoman Pan, et al. | 2023‑11‑15 | `Template:` [chain-of-note-wiki](https://python.langchain.com/docs/templates/chain-of-note-wiki)
|
||||
| `2310.11511v1` [Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection](http://arxiv.org/abs/2310.11511v1) | Akari Asai, Zeqiu Wu, Yizhong Wang, et al. | 2023‑10‑17 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), `Cookbook:` [Langgraph Self Rag](https://github.com/langchain-ai/langchain/blob/master/cookbook/langgraph_self_rag.ipynb)
|
||||
| `2310.06117v2` [Take a Step Back: Evoking Reasoning via Abstraction in Large Language Models](http://arxiv.org/abs/2310.06117v2) | Huaixiu Steven Zheng, Swaroop Mishra, Xinyun Chen, et al. | 2023‑10‑09 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), `Template:` [stepback-qa-prompting](https://python.langchain.com/docs/templates/stepback-qa-prompting), `Cookbook:` [Stepback-Qa](https://github.com/langchain-ai/langchain/blob/master/cookbook/stepback-qa.ipynb)
|
||||
| `2310.06117v2` [Take a Step Back: Evoking Reasoning via Abstraction in Large Language Models](http://arxiv.org/abs/2310.06117v2) | Huaixiu Steven Zheng, Swaroop Mishra, Xinyun Chen, et al. | 2023‑10‑09 | `Template:` [stepback-qa-prompting](https://python.langchain.com/docs/templates/stepback-qa-prompting), `Cookbook:` [Stepback-Qa](https://github.com/langchain-ai/langchain/blob/master/cookbook/stepback-qa.ipynb)
|
||||
| `2307.15337v3` [Skeleton-of-Thought: Prompting LLMs for Efficient Parallel Generation](http://arxiv.org/abs/2307.15337v3) | Xuefei Ning, Zinan Lin, Zixuan Zhou, et al. | 2023‑07‑28 | `Template:` [skeleton-of-thought](https://python.langchain.com/docs/templates/skeleton-of-thought)
|
||||
| `2307.09288v2` [Llama 2: Open Foundation and Fine-Tuned Chat Models](http://arxiv.org/abs/2307.09288v2) | Hugo Touvron, Louis Martin, Kevin Stone, et al. | 2023‑07‑18 | `Cookbook:` [Semi Structured Rag](https://github.com/langchain-ai/langchain/blob/master/cookbook/Semi_Structured_RAG.ipynb)
|
||||
| `2307.03172v3` [Lost in the Middle: How Language Models Use Long Contexts](http://arxiv.org/abs/2307.03172v3) | Nelson F. Liu, Kevin Lin, John Hewitt, et al. | 2023‑07‑06 | `Docs:` [docs/how_to/long_context_reorder](https://python.langchain.com/v0.2/docs/how_to/long_context_reorder)
|
||||
@@ -35,24 +34,21 @@ From the opposite direction, scientists use `LangChain` in research and referenc
|
||||
| `2304.03442v2` [Generative Agents: Interactive Simulacra of Human Behavior](http://arxiv.org/abs/2304.03442v2) | Joon Sung Park, Joseph C. O'Brien, Carrie J. Cai, et al. | 2023‑04‑07 | `Cookbook:` [Generative Agents Interactive Simulacra Of Human Behavior](https://github.com/langchain-ai/langchain/blob/master/cookbook/generative_agents_interactive_simulacra_of_human_behavior.ipynb), [Multiagent Bidding](https://github.com/langchain-ai/langchain/blob/master/cookbook/multiagent_bidding.ipynb)
|
||||
| `2303.17760v2` [CAMEL: Communicative Agents for "Mind" Exploration of Large Language Model Society](http://arxiv.org/abs/2303.17760v2) | Guohao Li, Hasan Abed Al Kader Hammoud, Hani Itani, et al. | 2023‑03‑31 | `Cookbook:` [Camel Role Playing](https://github.com/langchain-ai/langchain/blob/master/cookbook/camel_role_playing.ipynb)
|
||||
| `2303.17580v4` [HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in Hugging Face](http://arxiv.org/abs/2303.17580v4) | Yongliang Shen, Kaitao Song, Xu Tan, et al. | 2023‑03‑30 | `API:` [langchain_experimental.autonomous_agents](https://api.python.langchain.com/en/latest/experimental_api_reference.html#module-langchain_experimental.autonomous_agents), `Cookbook:` [Hugginggpt](https://github.com/langchain-ai/langchain/blob/master/cookbook/hugginggpt.ipynb)
|
||||
| `2301.10226v4` [A Watermark for Large Language Models](http://arxiv.org/abs/2301.10226v4) | John Kirchenbauer, Jonas Geiping, Yuxin Wen, et al. | 2023‑01‑24 | `API:` [langchain_community...OCIModelDeploymentTGI](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI.html#langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference), [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint)
|
||||
| `2212.10496v1` [Precise Zero-Shot Dense Retrieval without Relevance Labels](http://arxiv.org/abs/2212.10496v1) | Luyu Gao, Xueguang Ma, Jimmy Lin, et al. | 2022‑12‑20 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), `API:` [langchain...HypotheticalDocumentEmbedder](https://api.python.langchain.com/en/latest/chains/langchain.chains.hyde.base.HypotheticalDocumentEmbedder.html#langchain.chains.hyde.base.HypotheticalDocumentEmbedder), `Template:` [hyde](https://python.langchain.com/docs/templates/hyde), `Cookbook:` [Hypothetical Document Embeddings](https://github.com/langchain-ai/langchain/blob/master/cookbook/hypothetical_document_embeddings.ipynb)
|
||||
| `2301.10226v4` [A Watermark for Large Language Models](http://arxiv.org/abs/2301.10226v4) | John Kirchenbauer, Jonas Geiping, Yuxin Wen, et al. | 2023‑01‑24 | `API:` [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...OCIModelDeploymentTGI](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI.html#langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference)
|
||||
| `2212.10496v1` [Precise Zero-Shot Dense Retrieval without Relevance Labels](http://arxiv.org/abs/2212.10496v1) | Luyu Gao, Xueguang Ma, Jimmy Lin, et al. | 2022‑12‑20 | `API:` [langchain...HypotheticalDocumentEmbedder](https://api.python.langchain.com/en/latest/chains/langchain.chains.hyde.base.HypotheticalDocumentEmbedder.html#langchain.chains.hyde.base.HypotheticalDocumentEmbedder), `Template:` [hyde](https://python.langchain.com/docs/templates/hyde), `Cookbook:` [Hypothetical Document Embeddings](https://github.com/langchain-ai/langchain/blob/master/cookbook/hypothetical_document_embeddings.ipynb)
|
||||
| `2212.08073v1` [Constitutional AI: Harmlessness from AI Feedback](http://arxiv.org/abs/2212.08073v1) | Yuntao Bai, Saurav Kadavath, Sandipan Kundu, et al. | 2022‑12‑15 | `Docs:` [docs/versions/migrating_chains/constitutional_chain](https://python.langchain.com/v0.2/docs/versions/migrating_chains/constitutional_chain)
|
||||
| `2212.07425v3` [Robust and Explainable Identification of Logical Fallacies in Natural Language Arguments](http://arxiv.org/abs/2212.07425v3) | Zhivar Sourati, Vishnu Priya Prasanna Venkatesh, Darshan Deshpande, et al. | 2022‑12‑12 | `API:` [langchain_experimental.fallacy_removal](https://api.python.langchain.com/en/latest/experimental_api_reference.html#module-langchain_experimental.fallacy_removal)
|
||||
| `2211.13892v2` [Complementary Explanations for Effective In-Context Learning](http://arxiv.org/abs/2211.13892v2) | Xi Ye, Srinivasan Iyer, Asli Celikyilmaz, et al. | 2022‑11‑25 | `API:` [langchain_core...MaxMarginalRelevanceExampleSelector](https://api.python.langchain.com/en/latest/example_selectors/langchain_core.example_selectors.semantic_similarity.MaxMarginalRelevanceExampleSelector.html#langchain_core.example_selectors.semantic_similarity.MaxMarginalRelevanceExampleSelector)
|
||||
| `2211.10435v2` [PAL: Program-aided Language Models](http://arxiv.org/abs/2211.10435v2) | Luyu Gao, Aman Madaan, Shuyan Zhou, et al. | 2022‑11‑18 | `API:` [langchain_experimental.pal_chain](https://api.python.langchain.com/en/latest/experimental_api_reference.html#module-langchain_experimental.pal_chain), [langchain_experimental...PALChain](https://api.python.langchain.com/en/latest/pal_chain/langchain_experimental.pal_chain.base.PALChain.html#langchain_experimental.pal_chain.base.PALChain), `Cookbook:` [Program Aided Language Model](https://github.com/langchain-ai/langchain/blob/master/cookbook/program_aided_language_model.ipynb)
|
||||
| `2210.11934v2` [An Analysis of Fusion Functions for Hybrid Retrieval](http://arxiv.org/abs/2210.11934v2) | Sebastian Bruch, Siyu Gai, Amir Ingber | 2022‑10‑21 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
| `2210.03629v3` [ReAct: Synergizing Reasoning and Acting in Language Models](http://arxiv.org/abs/2210.03629v3) | Shunyu Yao, Jeffrey Zhao, Dian Yu, et al. | 2022‑10‑06 | `Docs:` [docs/integrations/tools/ionic_shopping](https://python.langchain.com/v0.2/docs/integrations/tools/ionic_shopping), [docs/integrations/providers/cohere](https://python.langchain.com/v0.2/docs/integrations/providers/cohere), [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), `API:` [langchain...create_react_agent](https://api.python.langchain.com/en/latest/agents/langchain.agents.react.agent.create_react_agent.html#langchain.agents.react.agent.create_react_agent), [langchain...TrajectoryEvalChain](https://api.python.langchain.com/en/latest/evaluation/langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain.html#langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain)
|
||||
| `2210.03629v3` [ReAct: Synergizing Reasoning and Acting in Language Models](http://arxiv.org/abs/2210.03629v3) | Shunyu Yao, Jeffrey Zhao, Dian Yu, et al. | 2022‑10‑06 | `Docs:` [docs/integrations/providers/cohere](https://python.langchain.com/v0.2/docs/integrations/providers/cohere), [docs/integrations/tools/ionic_shopping](https://python.langchain.com/v0.2/docs/integrations/tools/ionic_shopping), [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), `API:` [langchain...create_react_agent](https://api.python.langchain.com/en/latest/agents/langchain.agents.react.agent.create_react_agent.html#langchain.agents.react.agent.create_react_agent), [langchain...TrajectoryEvalChain](https://api.python.langchain.com/en/latest/evaluation/langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain.html#langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain)
|
||||
| `2209.10785v2` [Deep Lake: a Lakehouse for Deep Learning](http://arxiv.org/abs/2209.10785v2) | Sasun Hambardzumyan, Abhinav Tuli, Levon Ghukasyan, et al. | 2022‑09‑22 | `Docs:` [docs/integrations/providers/activeloop_deeplake](https://python.langchain.com/v0.2/docs/integrations/providers/activeloop_deeplake)
|
||||
| `2205.13147v4` [Matryoshka Representation Learning](http://arxiv.org/abs/2205.13147v4) | Aditya Kusupati, Gantavya Bhatt, Aniket Rege, et al. | 2022‑05‑26 | `Docs:` [docs/integrations/providers/snowflake](https://python.langchain.com/v0.2/docs/integrations/providers/snowflake)
|
||||
| `2205.12654v1` [Bitext Mining Using Distilled Sentence Representations for Low-Resource Languages](http://arxiv.org/abs/2205.12654v1) | Kevin Heffernan, Onur Çelebi, Holger Schwenk | 2022‑05‑25 | `API:` [langchain_community...LaserEmbeddings](https://api.python.langchain.com/en/latest/embeddings/langchain_community.embeddings.laser.LaserEmbeddings.html#langchain_community.embeddings.laser.LaserEmbeddings)
|
||||
| `2204.00498v1` [Evaluating the Text-to-SQL Capabilities of Large Language Models](http://arxiv.org/abs/2204.00498v1) | Nitarshan Rajkumar, Raymond Li, Dzmitry Bahdanau | 2022‑03‑15 | `Docs:` [docs/tutorials/sql_qa](https://python.langchain.com/v0.2/docs/tutorials/sql_qa), `API:` [langchain_community...SQLDatabase](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.sql_database.SQLDatabase.html#langchain_community.utilities.sql_database.SQLDatabase), [langchain_community...SparkSQL](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.spark_sql.SparkSQL.html#langchain_community.utilities.spark_sql.SparkSQL)
|
||||
| `2202.00666v5` [Locally Typical Sampling](http://arxiv.org/abs/2202.00666v5) | Clara Meister, Tiago Pimentel, Gian Wiher, et al. | 2022‑02‑01 | `API:` [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference), [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint)
|
||||
| `2112.01488v3` [ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction](http://arxiv.org/abs/2112.01488v3) | Keshav Santhanam, Omar Khattab, Jon Saad-Falcon, et al. | 2021‑12‑02 | `Docs:` [docs/integrations/retrievers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/retrievers/ragatouille), [docs/integrations/providers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/providers/ragatouille), [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), [docs/integrations/providers/dspy](https://python.langchain.com/v0.2/docs/integrations/providers/dspy)
|
||||
| `2204.00498v1` [Evaluating the Text-to-SQL Capabilities of Large Language Models](http://arxiv.org/abs/2204.00498v1) | Nitarshan Rajkumar, Raymond Li, Dzmitry Bahdanau | 2022‑03‑15 | `Docs:` [docs/tutorials/sql_qa](https://python.langchain.com/v0.2/docs/tutorials/sql_qa), `API:` [langchain_community...SparkSQL](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.spark_sql.SparkSQL.html#langchain_community.utilities.spark_sql.SparkSQL), [langchain_community...SQLDatabase](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.sql_database.SQLDatabase.html#langchain_community.utilities.sql_database.SQLDatabase)
|
||||
| `2202.00666v5` [Locally Typical Sampling](http://arxiv.org/abs/2202.00666v5) | Clara Meister, Tiago Pimentel, Gian Wiher, et al. | 2022‑02‑01 | `API:` [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference)
|
||||
| `2112.01488v3` [ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction](http://arxiv.org/abs/2112.01488v3) | Keshav Santhanam, Omar Khattab, Jon Saad-Falcon, et al. | 2021‑12‑02 | `Docs:` [docs/integrations/retrievers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/retrievers/ragatouille), [docs/integrations/providers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/providers/ragatouille), [docs/integrations/providers/dspy](https://python.langchain.com/v0.2/docs/integrations/providers/dspy)
|
||||
| `2103.00020v1` [Learning Transferable Visual Models From Natural Language Supervision](http://arxiv.org/abs/2103.00020v1) | Alec Radford, Jong Wook Kim, Chris Hallacy, et al. | 2021‑02‑26 | `API:` [langchain_experimental.open_clip](https://api.python.langchain.com/en/latest/experimental_api_reference.html#module-langchain_experimental.open_clip)
|
||||
| `2005.14165v4` [Language Models are Few-Shot Learners](http://arxiv.org/abs/2005.14165v4) | Tom B. Brown, Benjamin Mann, Nick Ryder, et al. | 2020‑05‑28 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
| `2005.11401v4` [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](http://arxiv.org/abs/2005.11401v4) | Patrick Lewis, Ethan Perez, Aleksandra Piktus, et al. | 2020‑05‑22 | `Docs:` [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
| `1909.05858v2` [CTRL: A Conditional Transformer Language Model for Controllable Generation](http://arxiv.org/abs/1909.05858v2) | Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, et al. | 2019‑09‑11 | `API:` [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference), [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint)
|
||||
| `1909.05858v2` [CTRL: A Conditional Transformer Language Model for Controllable Generation](http://arxiv.org/abs/1909.05858v2) | Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, et al. | 2019‑09‑11 | `API:` [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference)
|
||||
|
||||
## Adaptive-RAG: Learning to Adapt Retrieval-Augmented Large Language Models through Question Complexity
|
||||
|
||||
@@ -107,29 +103,6 @@ the self-discovered reasoning structures are universally applicable across
|
||||
model families: from PaLM 2-L to GPT-4, and from GPT-4 to Llama2, and share
|
||||
commonalities with human reasoning patterns.
|
||||
|
||||
## RAG-Fusion: a New Take on Retrieval-Augmented Generation
|
||||
|
||||
- **Authors:** Zackary Rackauckas
|
||||
- **arXiv id:** [2402.03367v2](http://arxiv.org/abs/2402.03367v2) **Published Date:** 2024-01-31
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
|
||||
**Abstract:** Infineon has identified a need for engineers, account managers, and customers
|
||||
to rapidly obtain product information. This problem is traditionally addressed
|
||||
with retrieval-augmented generation (RAG) chatbots, but in this study, I
|
||||
evaluated the use of the newly popularized RAG-Fusion method. RAG-Fusion
|
||||
combines RAG and reciprocal rank fusion (RRF) by generating multiple queries,
|
||||
reranking them with reciprocal scores and fusing the documents and scores.
|
||||
Through manually evaluating answers on accuracy, relevance, and
|
||||
comprehensiveness, I found that RAG-Fusion was able to provide accurate and
|
||||
comprehensive answers due to the generated queries contextualizing the original
|
||||
query from various perspectives. However, some answers strayed off topic when
|
||||
the generated queries' relevance to the original query is insufficient. This
|
||||
research marks significant progress in artificial intelligence (AI) and natural
|
||||
language processing (NLP) applications and demonstrates transformations in a
|
||||
global and multi-industry context.
|
||||
|
||||
## RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval
|
||||
|
||||
- **Authors:** Parth Sarthi, Salman Abdullah, Aditi Tuli, et al.
|
||||
@@ -324,7 +297,6 @@ to these models.
|
||||
- **arXiv id:** [2310.06117v2](http://arxiv.org/abs/2310.06117v2) **Published Date:** 2023-10-09
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
- **Template:** [stepback-qa-prompting](https://python.langchain.com/docs/templates/stepback-qa-prompting)
|
||||
- **Cookbook:** [stepback-qa](https://github.com/langchain-ai/langchain/blob/master/cookbook/stepback-qa.ipynb)
|
||||
|
||||
@@ -627,7 +599,7 @@ realization of artificial general intelligence.
|
||||
- **arXiv id:** [2301.10226v4](http://arxiv.org/abs/2301.10226v4) **Published Date:** 2023-01-24
|
||||
- **LangChain:**
|
||||
|
||||
- **API Reference:** [langchain_community...OCIModelDeploymentTGI](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI.html#langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference), [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint)
|
||||
- **API Reference:** [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...OCIModelDeploymentTGI](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI.html#langchain_community.llms.oci_data_science_model_deployment_endpoint.OCIModelDeploymentTGI), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference)
|
||||
|
||||
**Abstract:** Potential harms of large language models can be mitigated by watermarking
|
||||
model output, i.e., embedding signals into generated text that are invisible to
|
||||
@@ -649,7 +621,6 @@ family, and discuss robustness and security.
|
||||
- **arXiv id:** [2212.10496v1](http://arxiv.org/abs/2212.10496v1) **Published Date:** 2022-12-20
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
- **API Reference:** [langchain...HypotheticalDocumentEmbedder](https://api.python.langchain.com/en/latest/chains/langchain.chains.hyde.base.HypotheticalDocumentEmbedder.html#langchain.chains.hyde.base.HypotheticalDocumentEmbedder)
|
||||
- **Template:** [hyde](https://python.langchain.com/docs/templates/hyde)
|
||||
- **Cookbook:** [hypothetical_document_embeddings](https://github.com/langchain-ai/langchain/blob/master/cookbook/hypothetical_document_embeddings.ipynb)
|
||||
@@ -786,32 +757,13 @@ accuracy on the GSM8K benchmark of math word problems, surpassing PaLM-540B
|
||||
which uses chain-of-thought by absolute 15% top-1. Our code and data are
|
||||
publicly available at http://reasonwithpal.com/ .
|
||||
|
||||
## An Analysis of Fusion Functions for Hybrid Retrieval
|
||||
|
||||
- **Authors:** Sebastian Bruch, Siyu Gai, Amir Ingber
|
||||
- **arXiv id:** [2210.11934v2](http://arxiv.org/abs/2210.11934v2) **Published Date:** 2022-10-21
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
|
||||
**Abstract:** We study hybrid search in text retrieval where lexical and semantic search
|
||||
are fused together with the intuition that the two are complementary in how
|
||||
they model relevance. In particular, we examine fusion by a convex combination
|
||||
(CC) of lexical and semantic scores, as well as the Reciprocal Rank Fusion
|
||||
(RRF) method, and identify their advantages and potential pitfalls. Contrary to
|
||||
existing studies, we find RRF to be sensitive to its parameters; that the
|
||||
learning of a CC fusion is generally agnostic to the choice of score
|
||||
normalization; that CC outperforms RRF in in-domain and out-of-domain settings;
|
||||
and finally, that CC is sample efficient, requiring only a small set of
|
||||
training examples to tune its only parameter to a target domain.
|
||||
|
||||
## ReAct: Synergizing Reasoning and Acting in Language Models
|
||||
|
||||
- **Authors:** Shunyu Yao, Jeffrey Zhao, Dian Yu, et al.
|
||||
- **arXiv id:** [2210.03629v3](http://arxiv.org/abs/2210.03629v3) **Published Date:** 2022-10-06
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/integrations/tools/ionic_shopping](https://python.langchain.com/v0.2/docs/integrations/tools/ionic_shopping), [docs/integrations/providers/cohere](https://python.langchain.com/v0.2/docs/integrations/providers/cohere), [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
- **Documentation:** [docs/integrations/providers/cohere](https://python.langchain.com/v0.2/docs/integrations/providers/cohere), [docs/integrations/tools/ionic_shopping](https://python.langchain.com/v0.2/docs/integrations/tools/ionic_shopping), [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
- **API Reference:** [langchain...create_react_agent](https://api.python.langchain.com/en/latest/agents/langchain.agents.react.agent.create_react_agent.html#langchain.agents.react.agent.create_react_agent), [langchain...TrajectoryEvalChain](https://api.python.langchain.com/en/latest/evaluation/langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain.html#langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain)
|
||||
|
||||
**Abstract:** While large language models (LLMs) have demonstrated impressive capabilities
|
||||
@@ -926,7 +878,7 @@ encoders, mine bitexts, and validate the bitexts by training NMT systems.
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/tutorials/sql_qa](https://python.langchain.com/v0.2/docs/tutorials/sql_qa)
|
||||
- **API Reference:** [langchain_community...SQLDatabase](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.sql_database.SQLDatabase.html#langchain_community.utilities.sql_database.SQLDatabase), [langchain_community...SparkSQL](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.spark_sql.SparkSQL.html#langchain_community.utilities.spark_sql.SparkSQL)
|
||||
- **API Reference:** [langchain_community...SparkSQL](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.spark_sql.SparkSQL.html#langchain_community.utilities.spark_sql.SparkSQL), [langchain_community...SQLDatabase](https://api.python.langchain.com/en/latest/utilities/langchain_community.utilities.sql_database.SQLDatabase.html#langchain_community.utilities.sql_database.SQLDatabase)
|
||||
|
||||
**Abstract:** We perform an empirical evaluation of Text-to-SQL capabilities of the Codex
|
||||
language model. We find that, without any finetuning, Codex is a strong
|
||||
@@ -942,7 +894,7 @@ few-shot examples.
|
||||
- **arXiv id:** [2202.00666v5](http://arxiv.org/abs/2202.00666v5) **Published Date:** 2022-02-01
|
||||
- **LangChain:**
|
||||
|
||||
- **API Reference:** [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference), [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint)
|
||||
- **API Reference:** [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference)
|
||||
|
||||
**Abstract:** Today's probabilistic language generators fall short when it comes to
|
||||
producing coherent and fluent text despite the fact that the underlying models
|
||||
@@ -971,7 +923,7 @@ reducing degenerate repetitions.
|
||||
- **arXiv id:** [2112.01488v3](http://arxiv.org/abs/2112.01488v3) **Published Date:** 2021-12-02
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/integrations/retrievers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/retrievers/ragatouille), [docs/integrations/providers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/providers/ragatouille), [docs/concepts](https://python.langchain.com/v0.2/docs/concepts), [docs/integrations/providers/dspy](https://python.langchain.com/v0.2/docs/integrations/providers/dspy)
|
||||
- **Documentation:** [docs/integrations/retrievers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/retrievers/ragatouille), [docs/integrations/providers/ragatouille](https://python.langchain.com/v0.2/docs/integrations/providers/ragatouille), [docs/integrations/providers/dspy](https://python.langchain.com/v0.2/docs/integrations/providers/dspy)
|
||||
|
||||
**Abstract:** Neural information retrieval (IR) has greatly advanced search and other
|
||||
knowledge-intensive language tasks. While many neural IR methods encode queries
|
||||
@@ -1016,77 +968,13 @@ zero-shot without needing to use any of the 1.28 million training examples it
|
||||
was trained on. We release our code and pre-trained model weights at
|
||||
https://github.com/OpenAI/CLIP.
|
||||
|
||||
## Language Models are Few-Shot Learners
|
||||
|
||||
- **Authors:** Tom B. Brown, Benjamin Mann, Nick Ryder, et al.
|
||||
- **arXiv id:** [2005.14165v4](http://arxiv.org/abs/2005.14165v4) **Published Date:** 2020-05-28
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
|
||||
**Abstract:** Recent work has demonstrated substantial gains on many NLP tasks and
|
||||
benchmarks by pre-training on a large corpus of text followed by fine-tuning on
|
||||
a specific task. While typically task-agnostic in architecture, this method
|
||||
still requires task-specific fine-tuning datasets of thousands or tens of
|
||||
thousands of examples. By contrast, humans can generally perform a new language
|
||||
task from only a few examples or from simple instructions - something which
|
||||
current NLP systems still largely struggle to do. Here we show that scaling up
|
||||
language models greatly improves task-agnostic, few-shot performance, sometimes
|
||||
even reaching competitiveness with prior state-of-the-art fine-tuning
|
||||
approaches. Specifically, we train GPT-3, an autoregressive language model with
|
||||
175 billion parameters, 10x more than any previous non-sparse language model,
|
||||
and test its performance in the few-shot setting. For all tasks, GPT-3 is
|
||||
applied without any gradient updates or fine-tuning, with tasks and few-shot
|
||||
demonstrations specified purely via text interaction with the model. GPT-3
|
||||
achieves strong performance on many NLP datasets, including translation,
|
||||
question-answering, and cloze tasks, as well as several tasks that require
|
||||
on-the-fly reasoning or domain adaptation, such as unscrambling words, using a
|
||||
novel word in a sentence, or performing 3-digit arithmetic. At the same time,
|
||||
we also identify some datasets where GPT-3's few-shot learning still struggles,
|
||||
as well as some datasets where GPT-3 faces methodological issues related to
|
||||
training on large web corpora. Finally, we find that GPT-3 can generate samples
|
||||
of news articles which human evaluators have difficulty distinguishing from
|
||||
articles written by humans. We discuss broader societal impacts of this finding
|
||||
and of GPT-3 in general.
|
||||
|
||||
## Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
|
||||
|
||||
- **Authors:** Patrick Lewis, Ethan Perez, Aleksandra Piktus, et al.
|
||||
- **arXiv id:** [2005.11401v4](http://arxiv.org/abs/2005.11401v4) **Published Date:** 2020-05-22
|
||||
- **LangChain:**
|
||||
|
||||
- **Documentation:** [docs/concepts](https://python.langchain.com/v0.2/docs/concepts)
|
||||
|
||||
**Abstract:** Large pre-trained language models have been shown to store factual knowledge
|
||||
in their parameters, and achieve state-of-the-art results when fine-tuned on
|
||||
downstream NLP tasks. However, their ability to access and precisely manipulate
|
||||
knowledge is still limited, and hence on knowledge-intensive tasks, their
|
||||
performance lags behind task-specific architectures. Additionally, providing
|
||||
provenance for their decisions and updating their world knowledge remain open
|
||||
research problems. Pre-trained models with a differentiable access mechanism to
|
||||
explicit non-parametric memory can overcome this issue, but have so far been
|
||||
only investigated for extractive downstream tasks. We explore a general-purpose
|
||||
fine-tuning recipe for retrieval-augmented generation (RAG) -- models which
|
||||
combine pre-trained parametric and non-parametric memory for language
|
||||
generation. We introduce RAG models where the parametric memory is a
|
||||
pre-trained seq2seq model and the non-parametric memory is a dense vector index
|
||||
of Wikipedia, accessed with a pre-trained neural retriever. We compare two RAG
|
||||
formulations, one which conditions on the same retrieved passages across the
|
||||
whole generated sequence, the other can use different passages per token. We
|
||||
fine-tune and evaluate our models on a wide range of knowledge-intensive NLP
|
||||
tasks and set the state-of-the-art on three open domain QA tasks, outperforming
|
||||
parametric seq2seq models and task-specific retrieve-and-extract architectures.
|
||||
For language generation tasks, we find that RAG models generate more specific,
|
||||
diverse and factual language than a state-of-the-art parametric-only seq2seq
|
||||
baseline.
|
||||
|
||||
## CTRL: A Conditional Transformer Language Model for Controllable Generation
|
||||
|
||||
- **Authors:** Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, et al.
|
||||
- **arXiv id:** [1909.05858v2](http://arxiv.org/abs/1909.05858v2) **Published Date:** 2019-09-11
|
||||
- **LangChain:**
|
||||
|
||||
- **API Reference:** [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference), [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint)
|
||||
- **API Reference:** [langchain_community...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_community.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_huggingface...HuggingFaceEndpoint](https://api.python.langchain.com/en/latest/llms/langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint.html#langchain_huggingface.llms.huggingface_endpoint.HuggingFaceEndpoint), [langchain_community...HuggingFaceTextGenInference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference.html#langchain_community.llms.huggingface_text_gen_inference.HuggingFaceTextGenInference)
|
||||
|
||||
**Abstract:** Large-scale language models show promising text generation capabilities, but
|
||||
users cannot easily control particular aspects of the generated text. We
|
||||
|
||||
@@ -15,6 +15,11 @@ The interfaces for core components like LLMs, vector stores, retrievers and more
|
||||
No third party integrations are defined here.
|
||||
The dependencies are kept purposefully very lightweight.
|
||||
|
||||
### Partner packages
|
||||
|
||||
While the long tail of integrations are in `langchain-community`, we split popular integrations into their own packages (e.g. `langchain-openai`, `langchain-anthropic`, etc).
|
||||
This was done in order to improve support for these important integrations.
|
||||
|
||||
### `langchain`
|
||||
|
||||
The main `langchain` package contains chains, agents, and retrieval strategies that make up an application's cognitive architecture.
|
||||
@@ -28,11 +33,6 @@ Key partner packages are separated out (see below).
|
||||
This contains all integrations for various components (LLMs, vector stores, retrievers).
|
||||
All dependencies in this package are optional to keep the package as lightweight as possible.
|
||||
|
||||
### Partner packages
|
||||
|
||||
While the long tail of integrations is in `langchain-community`, we split popular integrations into their own packages (e.g. `langchain-openai`, `langchain-anthropic`, etc).
|
||||
This was done in order to improve support for these important integrations.
|
||||
|
||||
### [`langgraph`](https://langchain-ai.github.io/langgraph)
|
||||
|
||||
`langgraph` is an extension of `langchain` aimed at
|
||||
@@ -61,28 +61,28 @@ A developer platform that lets you debug, test, evaluate, and monitor LLM applic
|
||||
## LangChain Expression Language (LCEL)
|
||||
<span data-heading-keywords="lcel"></span>
|
||||
|
||||
`LangChain Expression Language`, or `LCEL`, is a declarative way to chain LangChain components.
|
||||
LangChain Expression Language, or LCEL, is a declarative way to chain LangChain components.
|
||||
LCEL was designed from day 1 to **support putting prototypes in production, with no code changes**, from the simplest “prompt + LLM” chain to the most complex chains (we’ve seen folks successfully run LCEL chains with 100s of steps in production). To highlight a few of the reasons you might want to use LCEL:
|
||||
|
||||
- **First-class streaming support:**
|
||||
**First-class streaming support**
|
||||
When you build your chains with LCEL you get the best possible time-to-first-token (time elapsed until the first chunk of output comes out). For some chains this means eg. we stream tokens straight from an LLM to a streaming output parser, and you get back parsed, incremental chunks of output at the same rate as the LLM provider outputs the raw tokens.
|
||||
|
||||
- **Async support:**
|
||||
**Async support**
|
||||
Any chain built with LCEL can be called both with the synchronous API (eg. in your Jupyter notebook while prototyping) as well as with the asynchronous API (eg. in a [LangServe](/docs/langserve/) server). This enables using the same code for prototypes and in production, with great performance, and the ability to handle many concurrent requests in the same server.
|
||||
|
||||
- **Optimized parallel execution:**
|
||||
**Optimized parallel execution**
|
||||
Whenever your LCEL chains have steps that can be executed in parallel (eg if you fetch documents from multiple retrievers) we automatically do it, both in the sync and the async interfaces, for the smallest possible latency.
|
||||
|
||||
- **Retries and fallbacks:**
|
||||
**Retries and fallbacks**
|
||||
Configure retries and fallbacks for any part of your LCEL chain. This is a great way to make your chains more reliable at scale. We’re currently working on adding streaming support for retries/fallbacks, so you can get the added reliability without any latency cost.
|
||||
|
||||
- **Access intermediate results:**
|
||||
**Access intermediate results**
|
||||
For more complex chains it’s often very useful to access the results of intermediate steps even before the final output is produced. This can be used to let end-users know something is happening, or even just to debug your chain. You can stream intermediate results, and it’s available on every [LangServe](/docs/langserve) server.
|
||||
|
||||
- **Input and output schemas**
|
||||
**Input and output schemas**
|
||||
Input and output schemas give every LCEL chain Pydantic and JSONSchema schemas inferred from the structure of your chain. This can be used for validation of inputs and outputs, and is an integral part of LangServe.
|
||||
|
||||
- [**Seamless LangSmith tracing**](https://docs.smith.langchain.com)
|
||||
[**Seamless LangSmith tracing**](https://docs.smith.langchain.com)
|
||||
As your chains get more and more complex, it becomes increasingly important to understand what exactly is happening at every step.
|
||||
With LCEL, **all** steps are automatically logged to [LangSmith](https://docs.smith.langchain.com/) for maximum observability and debuggability.
|
||||
|
||||
@@ -186,7 +186,7 @@ For a full list of LangChain model providers with multimodal models, [check out
|
||||
<span data-heading-keywords="llm,llms"></span>
|
||||
|
||||
:::caution
|
||||
Pure text-in/text-out LLMs tend to be older or lower-level. Many new popular models are best used as [chat completion models](/docs/concepts/#chat-models),
|
||||
Pure text-in/text-out LLMs tend to be older or lower-level. Many popular models are best used as [chat completion models](/docs/concepts/#chat-models),
|
||||
even for non-chat use cases.
|
||||
|
||||
You are probably looking for [the section above instead](/docs/concepts/#chat-models).
|
||||
@@ -201,7 +201,7 @@ When messages are passed in as input, they will be formatted into a string under
|
||||
|
||||
LangChain does not host any LLMs, rather we rely on third party integrations.
|
||||
|
||||
For specifics on how to use LLMs, see the [how-to guides](/docs/how_to/#llms).
|
||||
For specifics on how to use LLMs, see the [relevant how-to guides here](/docs/how_to/#llms).
|
||||
|
||||
### Messages
|
||||
|
||||
@@ -215,7 +215,7 @@ LangChain has different message classes for different roles.
|
||||
The `content` property describes the content of the message.
|
||||
This can be a few different things:
|
||||
|
||||
- A string (most models deal with this type of content)
|
||||
- A string (most models deal this type of content)
|
||||
- A List of dictionaries (this is used for multimodal input, where the dictionary contains information about that input type and that input location)
|
||||
|
||||
Optionally, messages can have a `name` property which allows for differentiating between multiple speakers with the same role.
|
||||
@@ -365,18 +365,24 @@ See documentation for that [here](/docs/concepts/#function-tool-calling).
|
||||
|
||||
:::
|
||||
|
||||
`Output parser` is responsible for taking the output of a model and transforming it to a more suitable format for downstream tasks.
|
||||
Responsible for taking the output of a model and transforming it to a more suitable format for downstream tasks.
|
||||
Useful when you are using LLMs to generate structured data, or to normalize output from chat models and LLMs.
|
||||
|
||||
LangChain has lots of different types of output parsers. This is a list of output parsers LangChain supports. The table below has various pieces of information:
|
||||
|
||||
- **Name**: The name of the output parser
|
||||
- **Supports Streaming**: Whether the output parser supports streaming.
|
||||
- **Has Format Instructions**: Whether the output parser has format instructions. This is generally available except when (a) the desired schema is not specified in the prompt but rather in other parameters (like OpenAI function calling), or (b) when the OutputParser wraps another OutputParser.
|
||||
- **Calls LLM**: Whether this output parser itself calls an LLM. This is usually only done by output parsers that attempt to correct misformatted output.
|
||||
- **Input Type**: Expected input type. Most output parsers work on both strings and messages, but some (like OpenAI Functions) need a message with specific kwargs.
|
||||
- **Output Type**: The output type of the object returned by the parser.
|
||||
- **Description**: Our commentary on this output parser and when to use it.
|
||||
**Name**: The name of the output parser
|
||||
|
||||
**Supports Streaming**: Whether the output parser supports streaming.
|
||||
|
||||
**Has Format Instructions**: Whether the output parser has format instructions. This is generally available except when (a) the desired schema is not specified in the prompt but rather in other parameters (like OpenAI function calling), or (b) when the OutputParser wraps another OutputParser.
|
||||
|
||||
**Calls LLM**: Whether this output parser itself calls an LLM. This is usually only done by output parsers that attempt to correct misformatted output.
|
||||
|
||||
**Input Type**: Expected input type. Most output parsers work on both strings and messages, but some (like OpenAI Functions) need a message with specific kwargs.
|
||||
|
||||
**Output Type**: The output type of the object returned by the parser.
|
||||
|
||||
**Description**: Our commentary on this output parser and when to use it.
|
||||
|
||||
| Name | Supports Streaming | Has Format Instructions | Calls LLM | Input Type | Output Type | Description |
|
||||
|-----------------|--------------------|-------------------------------|-----------|----------------------------------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
@@ -528,10 +534,10 @@ Tools are needed whenever you want a model to control parts of your code or call
|
||||
|
||||
A tool consists of:
|
||||
|
||||
1. The `name` of the tool.
|
||||
2. A `description` of what the tool does.
|
||||
3. A `JSON schema` defining the inputs to the tool.
|
||||
4. A `function` (and, optionally, an async variant of the function).
|
||||
1. The name of the tool.
|
||||
2. A description of what the tool does.
|
||||
3. A JSON schema defining the inputs to the tool.
|
||||
4. A function (and, optionally, an async variant of the function).
|
||||
|
||||
When a tool is bound to a model, the name, description and JSON schema are provided as context to the model.
|
||||
Given a list of tools and a set of instructions, a model can request to call one or more tools with specific inputs.
|
||||
@@ -644,14 +650,14 @@ The results of those actions can then be fed back into the agent and it determin
|
||||
[LangGraph](https://github.com/langchain-ai/langgraph) is an extension of LangChain specifically aimed at creating highly controllable and customizable agents.
|
||||
Please check out that documentation for a more in depth overview of agent concepts.
|
||||
|
||||
There is a legacy `agent` concept in LangChain that we are moving towards deprecating: `AgentExecutor`.
|
||||
There is a legacy agent concept in LangChain that we are moving towards deprecating: `AgentExecutor`.
|
||||
AgentExecutor was essentially a runtime for agents.
|
||||
It was a great place to get started, however, it was not flexible enough as you started to have more customized agents.
|
||||
In order to solve that we built LangGraph to be this flexible, highly-controllable runtime.
|
||||
|
||||
If you are still using AgentExecutor, do not fear: we still have a guide on [how to use AgentExecutor](/docs/how_to/agent_executor).
|
||||
It is recommended, however, that you start to transition to LangGraph.
|
||||
In order to assist in this, we have put together a [transition guide on how to do so](/docs/how_to/migrate_agent).
|
||||
In order to assist in this we have put together a [transition guide on how to do so](/docs/how_to/migrate_agent).
|
||||
|
||||
#### ReAct agents
|
||||
<span data-heading-keywords="react,react agent"></span>
|
||||
@@ -737,7 +743,7 @@ callbacks to any child objects.
|
||||
:::important Async in Python<=3.10
|
||||
|
||||
Any `RunnableLambda`, a `RunnableGenerator`, or `Tool` that invokes other runnables
|
||||
and is running `async` in python<=3.10, will have to propagate callbacks to child
|
||||
and is running async in python<=3.10, will have to propagate callbacks to child
|
||||
objects manually. This is because LangChain cannot automatically propagate
|
||||
callbacks to child objects in this case.
|
||||
|
||||
@@ -867,7 +873,7 @@ Furthermore, using tokens can also improve efficiency, since the model processes
|
||||
### Function/tool calling
|
||||
|
||||
:::info
|
||||
We use the term `tool calling` interchangeably with `function calling`. Although
|
||||
We use the term tool calling interchangeably with function calling. Although
|
||||
function calling is sometimes meant to refer to invocations of a single function,
|
||||
we treat all models as though they can return multiple tool or function calls in
|
||||
each message.
|
||||
@@ -962,6 +968,7 @@ structured_llm.invoke("Tell me a joke about cats")
|
||||
|
||||
```
|
||||
Joke(setup='Why was the cat sitting on the computer?', punchline='To keep an eye on the mouse!', rating=None)
|
||||
|
||||
```
|
||||
|
||||
We recommend this method as a starting point when working with structured output:
|
||||
@@ -1100,11 +1107,7 @@ For a full list of model providers that support tool calling, [see this table](/
|
||||
|
||||
### Few-shot prompting
|
||||
|
||||
One of the most effective ways to improve model performance is to give a model examples of
|
||||
what you want it to do. The technique of adding example inputs and expected outputs
|
||||
to a model prompt is known as "few-shot prompting". The technique is based on the
|
||||
[Language Models are Few-Shot Learners](https://arxiv.org/abs/2005.14165) paper.
|
||||
There are a few things to think about when doing few-shot prompting:
|
||||
One of the most effective ways to improve model performance is to give a model examples of what you want it to do. The technique of adding example inputs and expected outputs to a model prompt is known as "few-shot prompting". There are a few things to think about when doing few-shot prompting:
|
||||
|
||||
1. How are examples generated?
|
||||
2. How many examples are in each prompt?
|
||||
@@ -1179,10 +1182,8 @@ You can see a case study of how Anthropic and OpenAI respond to different few-sh
|
||||
|
||||
### Retrieval
|
||||
|
||||
LLMs are trained on a large but fixed dataset, limiting their ability to reason over private or recent information.
|
||||
Fine-tuning an LLM with specific facts is one way to mitigate this, but is often [poorly suited for factual recall](https://www.anyscale.com/blog/fine-tuning-is-for-form-not-facts) and [can be costly](https://www.glean.com/blog/how-to-build-an-ai-assistant-for-the-enterprise).
|
||||
`Retrieval` is the process of providing relevant information to an LLM to improve its response for a given input.
|
||||
`Retrieval augmented generation` (`RAG`) [paper](https://arxiv.org/abs/2005.11401) is the process of grounding the LLM generation (output) using the retrieved information.
|
||||
LLMs are trained on a large but fixed dataset, limiting their ability to reason over private or recent information. Fine-tuning an LLM with specific facts is one way to mitigate this, but is often [poorly suited for factual recall](https://www.anyscale.com/blog/fine-tuning-is-for-form-not-facts) and [can be costly](https://www.glean.com/blog/how-to-build-an-ai-assistant-for-the-enterprise).
|
||||
Retrieval is the process of providing relevant information to an LLM to improve its response for a given input. Retrieval augmented generation (RAG) is the process of grounding the LLM generation (output) using the retrieved information.
|
||||
|
||||
:::tip
|
||||
|
||||
@@ -1202,12 +1203,12 @@ First, consider the user input(s) to your RAG system. Ideally, a RAG system can
|
||||
**Using an LLM to review and optionally modify the input is the central idea behind query translation.** This serves as a general buffer, optimizing raw user inputs for your retrieval system.
|
||||
For example, this can be as simple as extracting keywords or as complex as generating multiple sub-questions for a complex query.
|
||||
|
||||
| Name | When to use | Description |
|
||||
|---------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Name | When to use | Description |
|
||||
|---------------|-------------|-------------|
|
||||
| [Multi-query](/docs/how_to/MultiQueryRetriever/) | When you need to cover multiple perspectives of a question. | Rewrite the user question from multiple perspectives, retrieve documents for each rewritten question, return the unique documents for all queries. |
|
||||
| [Decomposition](https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb) | When a question can be broken down into smaller subproblems. | Decompose a question into a set of subproblems / questions, which can either be solved sequentially (use the answer from first + retrieval to answer the second) or in parallel (consolidate each answer into final answer). |
|
||||
| [Step-back](https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb) | When a higher-level conceptual understanding is required. | First prompt the LLM to ask a generic step-back question about higher-level concepts or principles, and retrieve relevant facts about them. Use this grounding to help answer the user question. [Paper](https://arxiv.org/pdf/2310.06117). |
|
||||
| [HyDE](https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb) | If you have challenges retrieving relevant documents using the raw user inputs. | Use an LLM to convert questions into hypothetical documents that answer the question. Use the embedded hypothetical documents to retrieve real documents with the premise that doc-doc similarity search can produce more relevant matches. [Paper](https://arxiv.org/abs/2212.10496). |
|
||||
| [Decomposition](https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb) | When a question can be broken down into smaller subproblems. | Decompose a question into a set of subproblems / questions, which can either be solved sequentially (use the answer from first + retrieval to answer the second) or in parallel (consolidate each answer into final answer). |
|
||||
| [Step-back](https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb) | When a higher-level conceptual understanding is required. | First prompt the LLM to ask a generic step-back question about higher-level concepts or principles, and retrieve relevant facts about them. Use this grounding to help answer the user question. |
|
||||
| [HyDE](https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb) | If you have challenges retrieving relevant documents using the raw user inputs. | Use an LLM to convert questions into hypothetical documents that answer the question. Use the embedded hypothetical documents to retrieve real documents with the premise that doc-doc similarity search can produce more relevant matches. |
|
||||
|
||||
:::tip
|
||||
|
||||
@@ -1281,11 +1282,11 @@ Fifth, consider ways to improve the quality of your similarity search itself. Em
|
||||
|
||||
There are some additional tricks to improve the quality of your retrieval. Embeddings excel at capturing semantic information, but may struggle with keyword-based queries. Many [vector stores](/docs/integrations/retrievers/pinecone_hybrid_search/) offer built-in [hybrid-search](https://docs.pinecone.io/guides/data/understanding-hybrid-search) to combine keyword and semantic similarity, which marries the benefits of both approaches. Furthermore, many vector stores have [maximal marginal relevance](https://python.langchain.com/v0.1/docs/modules/model_io/prompts/example_selectors/mmr/), which attempts to diversify the results of a search to avoid returning similar and redundant documents.
|
||||
|
||||
| Name | When to use | Description |
|
||||
|-------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| [ColBERT](/docs/integrations/providers/ragatouille/#using-colbert-as-a-reranker) | When higher granularity embeddings are needed. | ColBERT uses contextually influenced embeddings for each token in the document and query to get a granular query-document similarity score. [Paper](https://arxiv.org/abs/2112.01488). |
|
||||
| [Hybrid search](/docs/integrations/retrievers/pinecone_hybrid_search/) | When combining keyword-based and semantic similarity. | Hybrid search combines keyword and semantic similarity, marrying the benefits of both approaches. [Paper](https://arxiv.org/abs/2210.11934). |
|
||||
| [Maximal Marginal Relevance (MMR)](/docs/integrations/vectorstores/pinecone/#maximal-marginal-relevance-searches) | When needing to diversify search results. | MMR attempts to diversify the results of a search to avoid returning similar and redundant documents. |
|
||||
| Name | When to use | Description |
|
||||
|-------------------|----------------------------------------------------------|-------------|
|
||||
| [ColBERT](/docs/integrations/providers/ragatouille/#using-colbert-as-a-reranker) | When higher granularity embeddings are needed. | ColBERT uses contextually influenced embeddings for each token in the document and query to get a granular query-document similarity score. |
|
||||
| [Hybrid search](/docs/integrations/retrievers/pinecone_hybrid_search/) | When combining keyword-based and semantic similarity. | Hybrid search combines keyword and semantic similarity, marrying the benefits of both approaches. |
|
||||
| [Maximal Marginal Relevance (MMR)](/docs/integrations/vectorstores/pinecone/#maximal-marginal-relevance-searches) | When needing to diversify search results. | MMR attempts to diversify the results of a search to avoid returning similar and redundant documents. |
|
||||
|
||||
:::tip
|
||||
|
||||
@@ -1305,7 +1306,7 @@ Sixth, consider ways to filter or rank retrieved documents. This is very useful
|
||||
|
||||
:::tip
|
||||
|
||||
See our RAG from Scratch video on [RAG-Fusion](https://youtu.be/77qELPbNgxA?feature=shared) ([paper](https://arxiv.org/abs/2402.03367)), on approach for post-processing across multiple queries: Rewrite the user question from multiple perspectives, retrieve documents for each rewritten question, and combine the ranks of multiple search result lists to produce a single, unified ranking with [Reciprocal Rank Fusion (RRF)](https://towardsdatascience.com/forget-rag-the-future-is-rag-fusion-1147298d8ad1).
|
||||
See our RAG from Scratch video on [RAG-Fusion](https://youtu.be/77qELPbNgxA?feature=shared), on approach for post-processing across multiple queries: Rewrite the user question from multiple perspectives, retrieve documents for each rewritten question, and combine the ranks of multiple search result lists to produce a single, unified ranking with [Reciprocal Rank Fusion (RRF)](https://towardsdatascience.com/forget-rag-the-future-is-rag-fusion-1147298d8ad1).
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -24,16 +24,3 @@ for more information.
|
||||
Notably, Github doesn't allow this setting to be enabled for forks in **organizations** ([issue](https://github.com/orgs/community/discussions/5634)).
|
||||
If you are working in an organization, we recommend submitting your PR from a personal
|
||||
fork in order to enable this setting.
|
||||
|
||||
### Why hasn't my PR been reviewed?
|
||||
|
||||
Please reference our [Review Process](/docs/contributing/review_process/).
|
||||
|
||||
### Why was my PR closed?
|
||||
|
||||
Please reference our [Review Process](/docs/contributing/review_process/).
|
||||
|
||||
### I think my PR was closed in a way that didn't follow the review process. What should I do?
|
||||
|
||||
Tag `@efriis` in the PR comments referencing the portion of the review
|
||||
process that you believe was not followed. We'll take a look!
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
# Review Process
|
||||
|
||||
## Overview
|
||||
|
||||
This document outlines the process used by the LangChain maintainers for reviewing pull requests (PRs). The primary objective of this process is to enhance the LangChain developer experience.
|
||||
|
||||
## Review Statuses
|
||||
|
||||
We categorize PRs using three main statuses, which are marked as project item statuses in the right sidebar and can be viewed in detail [here](https://github.com/orgs/langchain-ai/projects/12/views/1).
|
||||
|
||||
- **Triage**:
|
||||
- Initial status for all newly submitted PRs.
|
||||
- Requires a maintainer to categorize it into one of the other statuses.
|
||||
|
||||
- **Needs Support**:
|
||||
- PRs that require community feedback or additional input before moving forward.
|
||||
- Automatically promoted to the backlog if it receives 5 upvotes.
|
||||
- An auto-comment is generated when this status is applied, explaining the flow and the upvote requirement.
|
||||
- If the PR remains in this status for 25 days, it will be marked as “stale” via auto-comment.
|
||||
- PRs will be auto-closed after 30 days if no further action is taken.
|
||||
|
||||
- **In Review**:
|
||||
- PRs that are actively under review by our team.
|
||||
- These are regularly reviewed and monitored.
|
||||
|
||||
**Note:** A PR may only have one status at a time.
|
||||
|
||||
**Note:** You may notice 3 additional statuses of Done, Closed, and Internal that
|
||||
are external to this lifecycle. Done and Closed PRs have been merged or closed,
|
||||
respectively. Internal is for PRs submitted by core maintainers, and these PRs are owned
|
||||
by the submitter.
|
||||
|
||||
## Review Guidelines
|
||||
|
||||
1. **PRs that touch /libs/core**:
|
||||
- PRs that directly impact core code and are likely to affect end users.
|
||||
- **Triage Guideline**: most PRs should either go straight to `In Review` or closed.
|
||||
- These PRs are given top priority and are reviewed the fastest.
|
||||
- PRs that don't have a **concise** descriptions of their motivation (either in PR summary of in a linked issue) are likely to be closed without an in-depth review. Please do not generate verbose PR descriptions with an LLM.
|
||||
- PRs that don't have unit tests are likely to be closed.
|
||||
- Feature requests should first be opened as a GitHub issue and discussed with the LangChain maintainers. Large PRs submitted without prior discussion are likely to be closed.
|
||||
|
||||
2. **PRs that touch /libs/langchain**:
|
||||
- High-impact PRs that are closely related to core PRs but slightly lower in priority.
|
||||
- **Triage Guideline**: most PRs should either go straight to `In Review` or closed.
|
||||
- These are reviewed and closed aggressively, similar to core PRs.
|
||||
- New feature requests should be discussed with the core maintainer team beforehand in an issue.
|
||||
|
||||
3. **PRs that touch /libs/partners/****:
|
||||
- PRs involving integration packages.
|
||||
- **Triage Guideline**: most PRs should either go straight to `In Review` or closed.
|
||||
- The review may be conducted by our team or handed off to the partner's development team, depending on the PR's content.
|
||||
- We maintain communication lines with most partner dev teams to facilitate this process.
|
||||
|
||||
4. **Community PRs**:
|
||||
- Most community PRs will get an initial status of "needs support".
|
||||
- **Triage Guideline**: most PRs should go to `Needs support`. Bugfixes on high-traffic integrations should go straight to `In review`.
|
||||
- **Triage Guideline**: all new features and integrations should go to `Needs support` and will be closed if they do not get enough support (measured by upvotes or comments).
|
||||
- PRs in the `Needs Support` status for 20 days are marked as “stale” and will be closed after 30 days if no action is taken.
|
||||
|
||||
5. **Documentation PRs**:
|
||||
- PRs that touch the documentation content in docs/docs.
|
||||
- **Triage Guideline**:
|
||||
- PRs that fix typos or small errors in a single file and pass CI should go straight to `In Review`.
|
||||
- PRs that make changes that have been discussed and agreed upon in an issue should go straight to `In Review`.
|
||||
- PRs that add new pages or change the structure of the documentation should go to `Needs Support`.
|
||||
- We strive to standardize documentation formats to streamline the review process.
|
||||
- CI jobs run against documentation to ensure adherence to standards, automating much of the review.
|
||||
|
||||
6. **PRs must be in English**:
|
||||
- PRs that are not in English will be closed without review.
|
||||
- This is to ensure that all maintainers can review the PRs effectively.
|
||||
|
||||
## How to see a PR's status
|
||||
|
||||
See screenshot:
|
||||
|
||||

|
||||
|
||||
*To see the status of all open PRs, please visit the [LangChain Project Board](https://github.com/orgs/langchain-ai/projects/12/views/2).*
|
||||
|
||||
## Review Prioritization
|
||||
|
||||
Our goal is to provide the best possible development experience by focusing on making software that:
|
||||
|
||||
- Works: Works as intended (is bug-free).
|
||||
- Is useful: Improves LLM app development with components that work off-the-shelf and runtimes that simplify app building.
|
||||
- Is easy: Is intuitive to use and well-documented.
|
||||
|
||||
We believe this process reflects our priorities and are open to feedback if you feel it does not.
|
||||
|
||||
## Github Discussion
|
||||
|
||||
We welcome your feedback on this process. Please feel free to add a comment in
|
||||
[this GitHub Discussion](https://github.com/langchain-ai/langchain/discussions/25920).
|
||||
@@ -461,7 +461,7 @@
|
||||
"id": "f8014c9d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, we can initialize the agent with the LLM, the prompt, and the tools. The agent is responsible for taking in input and deciding what actions to take. Crucially, the Agent does not execute those actions - that is done by the AgentExecutor (next step). For more information about how to think about these components, see our [conceptual guide](/docs/concepts/#agents).\n",
|
||||
"Now, we can initalize the agent with the LLM, the prompt, and the tools. The agent is responsible for taking in input and deciding what actions to take. Crucially, the Agent does not execute those actions - that is done by the AgentExecutor (next step). For more information about how to think about these components, see our [conceptual guide](/docs/concepts/#agents).\n",
|
||||
"\n",
|
||||
"Note that we are passing in the `model`, not `model_with_tools`. That is because `create_tool_calling_agent` will call `.bind_tools` for us under the hood."
|
||||
]
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
"\n",
|
||||
"When constructing an agent, you will need to provide it with a list of `Tool`s that it can use. Besides the actual function that is called, the Tool consists of several components:\n",
|
||||
"\n",
|
||||
"| Attribute | Type | Description |\n",
|
||||
"|---------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n",
|
||||
"| name | str | Must be unique within a set of tools provided to an LLM or agent. |\n",
|
||||
"| description | str | Describes what the tool does. Used as context by the LLM or agent. |\n",
|
||||
"| args_schema | langchain.pydantic_v1.BaseModel | Optional but recommended, and required if using callback handlers. It can be used to provide more information (e.g., few-shot examples) or validation for expected parameters. |\n",
|
||||
"| return_direct | boolean | Only relevant for agents. When True, after invoking the given tool, the agent will stop and return the result direcly to the user. |\n",
|
||||
"| Attribute | Type | Description |\n",
|
||||
"|-----------------|---------------------------|------------------------------------------------------------------------------------------------------------------|\n",
|
||||
"| name | str | Must be unique within a set of tools provided to an LLM or agent. |\n",
|
||||
"| description | str | Describes what the tool does. Used as context by the LLM or agent. |\n",
|
||||
"| args_schema | Pydantic BaseModel | Optional but recommended, can be used to provide more information (e.g., few-shot examples) or validation for expected parameters |\n",
|
||||
"| return_direct | boolean | Only relevant for agents. When True, after invoking the given tool, the agent will stop and return the result direcly to the user. |\n",
|
||||
"\n",
|
||||
"LangChain supports the creation of tools from:\n",
|
||||
"\n",
|
||||
|
||||
@@ -8,7 +8,7 @@ The Embeddings class is a class designed for interfacing with text embedding mod
|
||||
|
||||
Embeddings create a vector representation of a piece of text. This is useful because it means we can think about text in the vector space, and do things like semantic search where we look for pieces of text that are most similar in the vector space.
|
||||
|
||||
The base Embeddings class in LangChain provides two methods: one for embedding documents and one for embedding a query. The former, `.embed_documents`, takes as input multiple texts, while the latter, `.embed_query`, takes a single text. The reason for having these as two separate methods is that some embedding providers have different embedding methods for documents (to be searched over) vs queries (the search query itself).
|
||||
The base Embeddings class in LangChain provides two methods: one for embedding documents and one for embedding a query. The former, `.embed_documents`, takes as input multiple texts, while the latter, `.embed_query`, takes a single text. The reason for having these as two separate methods is that some embedding providers have different embedding methods for documents (to be searched over) vs queries (the search query itself).
|
||||
`.embed_query` will return a list of floats, whereas `.embed_documents` returns a list of lists of floats.
|
||||
|
||||
## Get started
|
||||
@@ -94,6 +94,15 @@ from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
embeddings_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
|
||||
```
|
||||
|
||||
You can also leave the `model_name` blank to use the default [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) model.
|
||||
|
||||
```python
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
embeddings_model = HuggingFaceEmbeddings()
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"\n",
|
||||
"## Architecture\n",
|
||||
"\n",
|
||||
"At a high-level, the steps of constructing a knowledge graph from text are:\n",
|
||||
"At a high-level, the steps of constructing a knowledge are from text are:\n",
|
||||
"\n",
|
||||
"1. **Extracting structured information from text**: Model is used to extract structured graph information from text.\n",
|
||||
"2. **Storing into graph database**: Storing the extracted structured graph information into a graph database enables downstream RAG applications\n",
|
||||
|
||||
@@ -9,7 +9,7 @@ functionality to install.
|
||||
|
||||
## Official release
|
||||
|
||||
To install the main `langchain` package, run:
|
||||
To install the main LangChain package, run:
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
@@ -26,7 +26,8 @@ import CodeBlock from "@theme/CodeBlock";
|
||||
|
||||
While this package acts as a sane starting point to using LangChain,
|
||||
much of the value of LangChain comes when integrating it with various model providers, datastores, etc.
|
||||
By default, the dependencies needed to do that are NOT installed. You will need to install the dependencies for specific integrations separately, which we show below.
|
||||
By default, the dependencies needed to do that are NOT installed. You will need to install the dependencies for specific integrations separately.
|
||||
We'll show how to do that in the next sections of this guide.
|
||||
|
||||
## Ecosystem packages
|
||||
|
||||
@@ -40,6 +41,14 @@ When installing a package, you do not need to explicitly install that package's
|
||||
However, you may choose to if you are using a feature only available in a certain version of that dependency.
|
||||
If you do, you should make sure that the installed or pinned version is compatible with any other integration packages you use.
|
||||
|
||||
### From source
|
||||
|
||||
If you want to install from source, you can do so by cloning the repo and be sure that the directory is `PATH/TO/REPO/langchain/libs/langchain` running:
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
### LangChain core
|
||||
The `langchain-core` package contains base abstractions that the rest of the LangChain ecosystem uses, along with the LangChain Expression Language. It is automatically installed by `langchain`, but can also be used separately. Install with:
|
||||
|
||||
@@ -47,18 +56,8 @@ The `langchain-core` package contains base abstractions that the rest of the Lan
|
||||
pip install langchain-core
|
||||
```
|
||||
|
||||
### Integration packages
|
||||
|
||||
Certain integrations like OpenAI and Anthropic have their own packages.
|
||||
Any integrations that require their own package will be documented as such in the [Integration docs](/docs/integrations/platforms/).
|
||||
You can see a list of all integration packages in the [API reference](https://api.python.langchain.com) under the "Partner libs" dropdown.
|
||||
To install one of these run:
|
||||
|
||||
```bash
|
||||
pip install langchain-openai
|
||||
```
|
||||
|
||||
Any integrations that haven't been split out into their own packages will live in the `langchain-community` package. Install with:
|
||||
### LangChain community
|
||||
The `langchain-community` package contains third-party integrations. Install with:
|
||||
|
||||
```bash
|
||||
pip install langchain-community
|
||||
@@ -90,7 +89,7 @@ pip install "langserve[all]"
|
||||
```
|
||||
for both client and server dependencies. Or `pip install "langserve[client]"` for client code, and `pip install "langserve[server]"` for server code.
|
||||
|
||||
### LangChain CLI
|
||||
## LangChain CLI
|
||||
The LangChain CLI is useful for working with LangChain templates and other LangServe projects.
|
||||
Install with:
|
||||
|
||||
@@ -106,13 +105,3 @@ If you are not using LangChain, you can install it with:
|
||||
```bash
|
||||
pip install langsmith
|
||||
```
|
||||
|
||||
### From source
|
||||
|
||||
If you want to install a package from source, you can do so by cloning the [main LangChain repo](https://github.com/langchain-ai/langchain), enter the directory of the package you want to install `PATH/TO/REPO/langchain/libs/{package}`, and run:
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
LangGraph, LangSmith SDK, and certain integration packages live outside the main LangChain repo. You can see [all repos here](https://github.com/langchain-ai).
|
||||
@@ -14,7 +14,7 @@
|
||||
"- [How to use a model to call tools](/docs/how_to/tool_calling)\n",
|
||||
":::\n",
|
||||
"\n",
|
||||
"In order to force our LLM to select a specific tool, we can use the `tool_choice` parameter to ensure certain behavior. First, let's define our model and tools:"
|
||||
"In order to force our LLM to spelect a specific tool, we can use the `tool_choice` parameter to ensure certain behavior. First, let's define our model and tools:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -129,13 +129,13 @@
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def count_emails(last_n_days: int) -> int:\n",
|
||||
" \"\"\"Dummy function to count number of e-mails. Returns 2 * last_n_days.\"\"\"\n",
|
||||
" \"\"\"Multiply two integers together.\"\"\"\n",
|
||||
" return last_n_days * 2\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def send_email(message: str, recipient: str) -> str:\n",
|
||||
" \"\"\"Dummy function for sending an e-mail.\"\"\"\n",
|
||||
" \"Add two integers.\"\n",
|
||||
" return f\"Successfully sent email to {recipient}.\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -50,18 +50,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "62e0dbc3",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from getpass import getpass\n",
|
||||
"\n",
|
||||
"os.environ[\"AI21_API_KEY\"] = getpass()"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -73,14 +73,14 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7c2e19d3-7c58-4470-9e1a-718b27a32056",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
|
||||
"# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"Enter your LangSmith API key: \")"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -115,15 +115,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "c40756fb-cbf8-4d44-a293-3989d707237e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_ai21 import ChatAI21\n",
|
||||
"\n",
|
||||
"llm = ChatAI21(model=\"jamba-instruct\", temperature=0)"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -135,8 +135,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "46b982dc-5d8a-46da-a711-81c03ccd6adc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content=\"J'adore programmer.\", id='run-2e8d16d6-a06e-45cb-8d0c-1c8208645033-0')"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"messages = [\n",
|
||||
" (\n",
|
||||
@@ -147,9 +160,7 @@
|
||||
"]\n",
|
||||
"ai_msg = llm.invoke(messages)\n",
|
||||
"ai_msg"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -163,6 +174,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "39353473fce5dd2e",
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
@@ -170,6 +182,18 @@
|
||||
"outputs_hidden": false
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content='Ich liebe das Programmieren.', id='run-e1bd82dc-1a7e-4b2e-bde9-ac995929ac0f-0')"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"\n",
|
||||
@@ -191,95 +215,7 @@
|
||||
" \"input\": \"I love programming.\",\n",
|
||||
" }\n",
|
||||
")"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": "# Tool Calls / Function Calling",
|
||||
"id": "39c0ccd229927eab"
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": "This example shows how to use tool calling with AI21 models:",
|
||||
"id": "2bf6b40be07fe2d4"
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from getpass import getpass\n",
|
||||
"\n",
|
||||
"from langchain_ai21.chat_models import ChatAI21\n",
|
||||
"from langchain_core.messages import HumanMessage, SystemMessage, ToolMessage\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langchain_core.utils.function_calling import convert_to_openai_tool\n",
|
||||
"\n",
|
||||
"os.environ[\"AI21_API_KEY\"] = getpass()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def get_weather(location: str, date: str) -> str:\n",
|
||||
" \"\"\"“Provide the weather for the specified location on the given date.”\"\"\"\n",
|
||||
" if location == \"New York\" and date == \"2024-12-05\":\n",
|
||||
" return \"25 celsius\"\n",
|
||||
" elif location == \"New York\" and date == \"2024-12-06\":\n",
|
||||
" return \"27 celsius\"\n",
|
||||
" elif location == \"London\" and date == \"2024-12-05\":\n",
|
||||
" return \"22 celsius\"\n",
|
||||
" return \"32 celsius\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"llm = ChatAI21(model=\"jamba-1.5-mini\")\n",
|
||||
"\n",
|
||||
"llm_with_tools = llm.bind_tools([convert_to_openai_tool(get_weather)])\n",
|
||||
"\n",
|
||||
"chat_messages = [\n",
|
||||
" SystemMessage(\n",
|
||||
" content=\"You are a helpful assistant. You can use the provided tools \"\n",
|
||||
" \"to assist with various tasks and provide accurate information\"\n",
|
||||
" )\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"human_messages = [\n",
|
||||
" HumanMessage(\n",
|
||||
" content=\"What is the forecast for the weather in New York on December 5, 2024?\"\n",
|
||||
" ),\n",
|
||||
" HumanMessage(content=\"And what about the 2024-12-06?\"),\n",
|
||||
" HumanMessage(content=\"OK, thank you.\"),\n",
|
||||
" HumanMessage(content=\"What is the expected weather in London on December 5, 2024?\"),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for human_message in human_messages:\n",
|
||||
" print(f\"User: {human_message.content}\")\n",
|
||||
" chat_messages.append(human_message)\n",
|
||||
" response = llm_with_tools.invoke(chat_messages)\n",
|
||||
" chat_messages.append(response)\n",
|
||||
" if response.tool_calls:\n",
|
||||
" tool_call = response.tool_calls[0]\n",
|
||||
" if tool_call[\"name\"] == \"get_weather\":\n",
|
||||
" weather = get_weather.invoke(\n",
|
||||
" {\n",
|
||||
" \"location\": tool_call[\"args\"][\"location\"],\n",
|
||||
" \"date\": tool_call[\"args\"][\"date\"],\n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
" chat_messages.append(\n",
|
||||
" ToolMessage(content=weather, tool_call_id=tool_call[\"id\"])\n",
|
||||
" )\n",
|
||||
" llm_answer = llm_with_tools.invoke(chat_messages)\n",
|
||||
" print(f\"Assistant: {llm_answer.content}\")\n",
|
||||
" else:\n",
|
||||
" print(f\"Assistant: {response.content}\")"
|
||||
],
|
||||
"id": "a181a28df77120fb",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"\n",
|
||||
"::: {.callout-warning}\n",
|
||||
"\n",
|
||||
"The Anthropic API officially supports tool-calling so this workaround is no longer needed. Please use [ChatAnthropic](/docs/integrations/chat/anthropic) with `langchain-anthropic>=0.1.15`.\n",
|
||||
"The Anthropic API officially supports tool-calling so this workaround is no longer needed. Please use [ChatAnthropic](/docs/integrations/chat/anthropic) with `langchain-anthropic>=0.1.5`.\n",
|
||||
"\n",
|
||||
":::\n",
|
||||
"\n",
|
||||
|
||||
@@ -404,7 +404,6 @@
|
||||
" max_new_tokens=512,\n",
|
||||
" do_sample=False,\n",
|
||||
" repetition_penalty=1.03,\n",
|
||||
" return_full_text=False,\n",
|
||||
" ),\n",
|
||||
" model_kwargs={\"quantization_config\": quantization_config},\n",
|
||||
")\n",
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The ScrapflyLoader also allows passing ScrapeConfig object for customizing the scrape request. See the documentation for the full feature details and their API params: https://scrapfly.io/docs/scrape-api/getting-started"
|
||||
"The ScrapflyLoader also allows passigng ScrapeConfig object for customizing the scrape request. See the documentation for the full feature details and their API params: https://scrapfly.io/docs/scrape-api/getting-started"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -6,272 +6,16 @@
|
||||
"source": [
|
||||
"# IPEX-LLM\n",
|
||||
"\n",
|
||||
"> [IPEX-LLM](https://github.com/intel-analytics/ipex-llm) is a PyTorch library for running LLM on Intel CPU and GPU (e.g., local PC with iGPU, discrete GPU such as Arc, Flex and Max) with very low latency.\n",
|
||||
"> [IPEX-LLM](https://github.com/intel-analytics/ipex-llm/) is a PyTorch library for running LLM on Intel CPU and GPU (e.g., local PC with iGPU, discrete GPU such as Arc, Flex and Max) with very low latency. \n",
|
||||
"\n",
|
||||
"- [IPEX-LLM on Intel GPU](#ipex-llm-on-intel-gpu)\n",
|
||||
"- [IPEX-LLM on Intel CPU](#ipex-llm-on-intel-cpu)\n",
|
||||
"\n",
|
||||
"## IPEX-LLM on Intel GPU\n",
|
||||
"\n",
|
||||
"This example goes over how to use LangChain to interact with `ipex-llm` for text generation on Intel GPU. \n",
|
||||
"\n",
|
||||
"> **Note**\n",
|
||||
">\n",
|
||||
"> It is recommended that only Windows users with Intel Arc A-Series GPU (except for Intel Arc A300-Series or Pro A60) run Jupyter notebook directly for section \"IPEX-LLM on Intel GPU\". For other cases (e.g. Linux users, Intel iGPU, etc.), it is recommended to run the code with Python scripts in terminal for best experiences.\n",
|
||||
"\n",
|
||||
"### Install Prerequisites\n",
|
||||
"To benefit from IPEX-LLM on Intel GPUs, there are several prerequisite steps for tools installation and environment preparation.\n",
|
||||
"\n",
|
||||
"If you are a Windows user, visit the [Install IPEX-LLM on Windows with Intel GPU Guide](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md), and follow [Install Prerequisites](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md#install-prerequisites) to update GPU driver (optional) and install Conda.\n",
|
||||
"\n",
|
||||
"If you are a Linux user, visit the [Install IPEX-LLM on Linux with Intel GPU](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md), and follow [**Install Prerequisites**](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md#install-prerequisites) to install GPU driver, Intel® oneAPI Base Toolkit 2024.0, and Conda.\n",
|
||||
"\n",
|
||||
"### Setup\n",
|
||||
"\n",
|
||||
"After the prerequisites installation, you should have created a conda environment with all prerequisites installed. **Start the jupyter service in this conda environment**:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -qU langchain langchain-community"
|
||||
"This example goes over how to use LangChain to interact with `ipex-llm` for text generation. \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Install IEPX-LLM for running LLMs locally on Intel GPU."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --pre --upgrade ipex-llm[xpu] --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"> **Note**\n",
|
||||
">\n",
|
||||
"> You can also use `https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/` as the extra-indel-url.\n",
|
||||
"\n",
|
||||
"### Runtime Configuration\n",
|
||||
"\n",
|
||||
"For optimal performance, it is recommended to set several environment variables based on your device:\n",
|
||||
"\n",
|
||||
"#### For Windows Users with Intel Core Ultra integrated GPU"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"SYCL_CACHE_PERSISTENT\"] = \"1\"\n",
|
||||
"os.environ[\"BIGDL_LLM_XMX_DISABLED\"] = \"1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### For Windows Users with Intel Arc A-Series GPU"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"SYCL_CACHE_PERSISTENT\"] = \"1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"> **Note**\n",
|
||||
">\n",
|
||||
"> For the first time that each model runs on Intel iGPU/Intel Arc A300-Series or Pro A60, it may take several minutes to compile.\n",
|
||||
">\n",
|
||||
"> For other GPU type, please refer to [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration) for Windows users, and [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration-1) for Linux users.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Basic Usage\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import warnings\n",
|
||||
"\n",
|
||||
"from langchain.chains import LLMChain\n",
|
||||
"from langchain_community.llms import IpexLLM\n",
|
||||
"from langchain_core.prompts import PromptTemplate\n",
|
||||
"\n",
|
||||
"warnings.filterwarnings(\"ignore\", category=UserWarning, message=\".*padding_mask.*\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Specify the prompt template for your model. In this example, we use the [vicuna-1.5](https://huggingface.co/lmsys/vicuna-7b-v1.5) model. If you're working with a different model, choose a proper template accordingly."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"template = \"USER: {question}\\nASSISTANT:\"\n",
|
||||
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Load the model locally using IpexLLM using `IpexLLM.from_model_id`. It will load the model directly in its Huggingface format and convert it automatically to low-bit format for inference. Set `device` to `\"xpu\"` in `model_kwargs` when initializing IpexLLM in order to load the LLM model to Intel GPU."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm = IpexLLM.from_model_id(\n",
|
||||
" model_id=\"lmsys/vicuna-7b-v1.5\",\n",
|
||||
" model_kwargs={\n",
|
||||
" \"temperature\": 0,\n",
|
||||
" \"max_length\": 64,\n",
|
||||
" \"trust_remote_code\": True,\n",
|
||||
" \"device\": \"xpu\",\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Use it in Chains"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm_chain = prompt | llm\n",
|
||||
"\n",
|
||||
"question = \"What is AI?\"\n",
|
||||
"output = llm_chain.invoke(question)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Save/Load Low-bit Model\n",
|
||||
"Alternatively, you might save the low-bit model to disk once and use `from_model_id_low_bit` instead of `from_model_id` to reload it for later use - even across different machines. It is space-efficient, as the low-bit model demands significantly less disk space than the original model. And `from_model_id_low_bit` is also more efficient than `from_model_id` in terms of speed and memory usage, as it skips the model conversion step. You can similarly set `device` to `\"xpu\"` in `model_kwargs` in order to load the LLM model to Intel GPU. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"To save the low-bit model, use `save_low_bit` as follows."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saved_lowbit_model_path = \"./vicuna-7b-1.5-low-bit\" # path to save low-bit model\n",
|
||||
"llm.model.save_low_bit(saved_lowbit_model_path)\n",
|
||||
"del llm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Load the model from saved lowbit model path as follows. \n",
|
||||
"> Note that the saved path for the low-bit model only includes the model itself but not the tokenizers. If you wish to have everything in one place, you will need to manually download or copy the tokenizer files from the original model's directory to the location where the low-bit model is saved."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm_lowbit = IpexLLM.from_model_id_low_bit(\n",
|
||||
" model_id=saved_lowbit_model_path,\n",
|
||||
" tokenizer_id=\"lmsys/vicuna-7b-v1.5\",\n",
|
||||
" # tokenizer_name=saved_lowbit_model_path, # copy the tokenizers to saved path if you want to use it this way\n",
|
||||
" model_kwargs={\n",
|
||||
" \"temperature\": 0,\n",
|
||||
" \"max_length\": 64,\n",
|
||||
" \"trust_remote_code\": True,\n",
|
||||
" \"device\": \"xpu\",\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Use the loaded model in Chains:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm_chain = prompt | llm_lowbit\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"question = \"What is AI?\"\n",
|
||||
"output = llm_chain.invoke(question)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## IPEX-LLM on Intel CPU\n",
|
||||
"\n",
|
||||
"This example goes over how to use LangChain to interact with `ipex-llm` for text generation on Intel CPU.\n",
|
||||
"\n",
|
||||
"### Setup"
|
||||
"## Setup"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -289,9 +33,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Install IEPX-LLM for running LLMs locally on Intel CPU:\n",
|
||||
"\n",
|
||||
"#### For Windows users:"
|
||||
"Install IEPX-LLM for running LLMs locally on Intel CPU."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -307,23 +49,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### For Linux users:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --pre --upgrade ipex-llm[all] --extra-index-url https://download.pytorch.org/whl/cpu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Basic Usage"
|
||||
"## Basic Usage"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -400,11 +126,15 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Save/Load Low-bit Model\n",
|
||||
"\n",
|
||||
"Alternatively, you might save the low-bit model to disk once and use `from_model_id_low_bit` instead of `from_model_id` to reload it for later use - even across different machines. It is space-efficient, as the low-bit model demands significantly less disk space than the original model. And `from_model_id_low_bit` is also more efficient than `from_model_id` in terms of speed and memory usage, as it skips the model conversion step.\n",
|
||||
"\n",
|
||||
"To save the low-bit model, use `save_low_bit` as follows:"
|
||||
"## Save/Load Low-bit Model\n",
|
||||
"Alternatively, you might save the low-bit model to disk once and use `from_model_id_low_bit` instead of `from_model_id` to reload it for later use - even across different machines. It is space-efficient, as the low-bit model demands significantly less disk space than the original model. And `from_model_id_low_bit` is also more efficient than `from_model_id` in terms of speed and memory usage, as it skips the model conversion step."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"To save the low-bit model, use `save_low_bit` as follows."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -422,8 +152,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Load the model from saved lowbit model path as follows.\n",
|
||||
"\n",
|
||||
"Load the model from saved lowbit model path as follows. \n",
|
||||
"> Note that the saved path for the low-bit model only includes the model itself but not the tokenizers. If you wish to have everything in one place, you will need to manually download or copy the tokenizer files from the original model's directory to the location where the low-bit model is saved."
|
||||
]
|
||||
},
|
||||
@@ -463,8 +192,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -70,10 +70,6 @@
|
||||
" predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)\n",
|
||||
" adapter_id=\"e2e_nlg\",\n",
|
||||
" adapter_version=1,\n",
|
||||
" **{\n",
|
||||
" \"api_token\": os.environ.get(\"HUGGING_FACE_HUB_TOKEN\"),\n",
|
||||
" \"max_new_tokens\": 5, # default is 256\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -91,10 +87,6 @@
|
||||
" predibase_api_key=os.environ.get(\"PREDIBASE_API_TOKEN\"),\n",
|
||||
" predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)\n",
|
||||
" adapter_id=\"predibase/e2e_nlg\",\n",
|
||||
" **{\n",
|
||||
" \"api_token\": os.environ.get(\"HUGGING_FACE_HUB_TOKEN\"),\n",
|
||||
" \"max_new_tokens\": 5, # default is 256\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -104,11 +96,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Optionally use `kwargs` to dynamically overwrite \"generate()\" settings.\n",
|
||||
"response = model.invoke(\n",
|
||||
" \"Can you recommend me a nice dry wine?\",\n",
|
||||
" **{\"temperature\": 0.5, \"max_new_tokens\": 1024},\n",
|
||||
")\n",
|
||||
"response = model.invoke(\"Can you recommend me a nice dry wine?\")\n",
|
||||
"print(response)"
|
||||
]
|
||||
},
|
||||
@@ -139,10 +127,6 @@
|
||||
" model=\"mistral-7b\",\n",
|
||||
" predibase_api_key=os.environ.get(\"PREDIBASE_API_TOKEN\"),\n",
|
||||
" predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)\n",
|
||||
" **{\n",
|
||||
" \"api_token\": os.environ.get(\"HUGGING_FACE_HUB_TOKEN\"),\n",
|
||||
" \"max_new_tokens\": 5, # default is 256\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -163,10 +147,6 @@
|
||||
" predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)\n",
|
||||
" adapter_id=\"e2e_nlg\",\n",
|
||||
" adapter_version=1,\n",
|
||||
" **{\n",
|
||||
" \"api_token\": os.environ.get(\"HUGGING_FACE_HUB_TOKEN\"),\n",
|
||||
" \"max_new_tokens\": 5, # default is 256\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -182,10 +162,6 @@
|
||||
" predibase_api_key=os.environ.get(\"PREDIBASE_API_TOKEN\"),\n",
|
||||
" predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)\n",
|
||||
" adapter_id=\"predibase/e2e_nlg\",\n",
|
||||
" **{\n",
|
||||
" \"api_token\": os.environ.get(\"HUGGING_FACE_HUB_TOKEN\"),\n",
|
||||
" \"max_new_tokens\": 5, # default is 256\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -283,10 +259,6 @@
|
||||
" predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)\n",
|
||||
" adapter_id=\"my-finetuned-adapter-id\", # Supports both, Predibase-hosted and HuggingFace-hosted adapter repositories.\n",
|
||||
" adapter_version=1, # required for Predibase-hosted adapters (ignored for HuggingFace-hosted adapters)\n",
|
||||
" **{\n",
|
||||
" \"api_token\": os.environ.get(\"HUGGING_FACE_HUB_TOKEN\"),\n",
|
||||
" \"max_new_tokens\": 5, # default is 256\n",
|
||||
" },\n",
|
||||
")\n",
|
||||
"# replace my-base-LLM with the name of your choice of a serverless base model in Predibase"
|
||||
]
|
||||
@@ -297,8 +269,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Optionally use `kwargs` to dynamically overwrite \"generate()\" settings.\n",
|
||||
"# response = model.invoke(\"Can you help categorize the following emails into positive, negative, and neutral?\", **{\"temperature\": 0.5, \"max_new_tokens\": 1024})"
|
||||
"# response = model.invoke(\"Can you help categorize the following emails into positive, negative, and neutral?\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -58,7 +58,7 @@ The value of image_url can be any of the following:
|
||||
|
||||
### Vertex AI
|
||||
|
||||
Access chat models like `Gemini` via Google Cloud.
|
||||
Access PaLM chat models like `chat-bison` and `codechat-bison` via Google Cloud.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
@@ -72,7 +72,7 @@ See a [usage example](/docs/integrations/chat/google_vertex_ai_palm).
|
||||
from langchain_google_vertexai import ChatVertexAI
|
||||
```
|
||||
|
||||
### Chat Anthropic on Vertex AI Model Garden
|
||||
### Chat Anthropic on Vertex AI
|
||||
|
||||
See a [usage example](/docs/integrations/llms/google_vertex_ai_palm).
|
||||
|
||||
@@ -80,114 +80,6 @@ See a [usage example](/docs/integrations/llms/google_vertex_ai_palm).
|
||||
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
|
||||
```
|
||||
|
||||
### Chat Llama on Vertex AI Model Garden
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlama
|
||||
```
|
||||
|
||||
### Chat Mistral on Vertex AI Model Garden
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistral
|
||||
```
|
||||
|
||||
### Chat Gemma local from Hugging Face
|
||||
|
||||
>Local `Gemma` model loaded from `HuggingFace`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaChatLocalHF
|
||||
```
|
||||
|
||||
### Chat Gemma local from Kaggle
|
||||
|
||||
>Local `Gemma` model loaded from `Kaggle`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaChatLocalKaggle
|
||||
```
|
||||
|
||||
### Chat Gemma on Vertex AI Model Garden
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGarden
|
||||
```
|
||||
|
||||
### Vertex AI image captioning chat
|
||||
|
||||
>Implementation of the `Image Captioning model` as a chat.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageCaptioningChat
|
||||
```
|
||||
|
||||
### Vertex AI image editor chat
|
||||
|
||||
>Given an image and a prompt, edit the image. Currently only supports mask-free editing.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageEditorChat
|
||||
```
|
||||
|
||||
### Vertex AI image generator chat
|
||||
|
||||
>Generates an image from a prompt.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChat
|
||||
```
|
||||
|
||||
### Vertex AI visual QnA chat
|
||||
|
||||
>Chat implementation of a visual QnA model
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIVisualQnAChat
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
### Google Generative AI
|
||||
@@ -222,63 +114,9 @@ See a [usage example](/docs/integrations/llms/google_vertex_ai_palm#vertex-model
|
||||
from langchain_google_vertexai import VertexAIModelGarden
|
||||
```
|
||||
|
||||
### Gemma local from Hugging Face
|
||||
|
||||
>Local `Gemma` model loaded from `HuggingFace`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaLocalHF
|
||||
```
|
||||
|
||||
### Gemma local from Kaggle
|
||||
|
||||
>Local `Gemma` model loaded from `Kaggle`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaLocalKaggle
|
||||
```
|
||||
|
||||
### Gemma on Vertex AI Model Garden
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaVertexAIModelGarden
|
||||
```
|
||||
|
||||
### Vertex AI image captioning
|
||||
|
||||
>Implementation of the `Image Captioning model` as an LLM.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageCaptioning
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### Google Generative AI embedding
|
||||
### Google Generative AI Embeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/google_generative_ai).
|
||||
|
||||
@@ -296,18 +134,6 @@ export GOOGLE_API_KEY=your-api-key
|
||||
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
||||
```
|
||||
|
||||
### Google Generative AI server-side embedding
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-genai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_genai.google_vector_store import ServerSideEmbedding
|
||||
```
|
||||
|
||||
### Vertex AI
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
@@ -322,7 +148,7 @@ See a [usage example](/docs/integrations/text_embedding/google_vertex_ai_palm).
|
||||
from langchain_google_vertexai import VertexAIEmbeddings
|
||||
```
|
||||
|
||||
### Palm embedding
|
||||
### Palm Embedding
|
||||
|
||||
We need to install `langchain-community` python package.
|
||||
|
||||
@@ -371,7 +197,6 @@ from langchain_google_community import BigQueryLoader
|
||||
### Bigtable
|
||||
|
||||
> [Google Cloud Bigtable](https://cloud.google.com/bigtable/docs) is Google's fully managed NoSQL Big Data database service in Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -387,7 +212,6 @@ from langchain_google_bigtable import BigtableLoader
|
||||
### Cloud SQL for MySQL
|
||||
|
||||
> [Google Cloud SQL for MySQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -397,13 +221,12 @@ pip install langchain-google-cloud-sql-mysql
|
||||
See [usage example](/docs/integrations/document_loaders/google_cloud_sql_mysql).
|
||||
|
||||
```python
|
||||
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLLoader
|
||||
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLDocumentLoader
|
||||
```
|
||||
|
||||
### Cloud SQL for SQL Server
|
||||
|
||||
> [Google Cloud SQL for SQL Server](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your SQL Server databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -419,7 +242,6 @@ from langchain_google_cloud_sql_mssql import MSSQLEngine, MSSQLLoader
|
||||
### Cloud SQL for PostgreSQL
|
||||
|
||||
> [Google Cloud SQL for PostgreSQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -504,7 +326,6 @@ from langchain_google_community import GoogleDriveLoader
|
||||
### Firestore (Native Mode)
|
||||
|
||||
> [Google Cloud Firestore](https://cloud.google.com/firestore/docs/) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -521,7 +342,6 @@ from langchain_google_firestore import FirestoreLoader
|
||||
|
||||
> [Google Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
> Firestore is the newest version of Datastore and introduces several improvements over Datastore.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -537,7 +357,6 @@ from langchain_google_datastore import DatastoreLoader
|
||||
### Memorystore for Redis
|
||||
|
||||
> [Google Cloud Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis) is a fully managed Redis service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Redis service without the burden of managing complex Redis deployments.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -547,13 +366,12 @@ pip install langchain-google-memorystore-redis
|
||||
See [usage example](/docs/integrations/document_loaders/google_memorystore_redis).
|
||||
|
||||
```python
|
||||
from langchain_google_memorystore_redis import MemorystoreDocumentLoader
|
||||
from langchain_google_memorystore_redis import MemorystoreLoader
|
||||
```
|
||||
|
||||
### Spanner
|
||||
|
||||
> [Google Cloud Spanner](https://cloud.google.com/spanner/docs) is a fully managed, mission-critical, relational database service on Google Cloud that offers transactional consistency at global scale, automatic, synchronous replication for high availability, and support for two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -672,7 +490,6 @@ from langchain.vectorstores import BigQueryVectorSearch
|
||||
### Memorystore for Redis
|
||||
|
||||
> [Google Cloud Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis) is a fully managed Redis service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Redis service without the burden of managing complex Redis deployments.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -688,7 +505,6 @@ from langchain_google_memorystore_redis import RedisVectorStore
|
||||
### Spanner
|
||||
|
||||
> [Google Cloud Spanner](https://cloud.google.com/spanner/docs) is a fully managed, mission-critical, relational database service on Google Cloud that offers transactional consistency at global scale, automatic, synchronous replication for high availability, and support for two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -704,7 +520,6 @@ from langchain_google_spanner import SpannerVectorStore
|
||||
### Firestore (Native Mode)
|
||||
|
||||
> [Google Cloud Firestore](https://cloud.google.com/firestore/docs/) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -714,13 +529,12 @@ pip install langchain-google-firestore
|
||||
See [usage example](/docs/integrations/vectorstores/google_firestore).
|
||||
|
||||
```python
|
||||
from langchain_google_firestore import FirestoreVectorStore
|
||||
from langchain_google_firestore import FirestoreVectorstore
|
||||
```
|
||||
|
||||
### Cloud SQL for MySQL
|
||||
|
||||
> [Google Cloud SQL for MySQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -736,7 +550,6 @@ from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLVectorStore
|
||||
### Cloud SQL for PostgreSQL
|
||||
|
||||
> [Google Cloud SQL for PostgreSQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -768,52 +581,6 @@ See a [usage example](/docs/integrations/vectorstores/google_vertex_ai_vector_se
|
||||
from langchain_google_vertexai import VectorSearchVectorStore
|
||||
```
|
||||
|
||||
### Vertex AI Vector Search with DataStore
|
||||
|
||||
> VectorSearch with DatasTore document storage.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/vectorstores/google_vertex_ai_vector_search/#optional--you-can-also-create-vectore-and-store-chunks-in-a-datastore).
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai import VectorSearchVectorStoreDatastore
|
||||
```
|
||||
|
||||
### VectorSearchVectorStoreGCS
|
||||
|
||||
> Alias of `VectorSearchVectorStore` for consistency
|
||||
> with the rest of vector stores with different document storage backends.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai import VectorSearchVectorStoreGCS
|
||||
```
|
||||
|
||||
### Google Generative AI Vector Store
|
||||
|
||||
> Currently, it computes the embedding vectors on the server side.
|
||||
> For more information visit [Guide](https://developers.generativeai.google/guide).
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-genai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_genai.google_vector_store import GoogleVectorStore
|
||||
```
|
||||
|
||||
### ScaNN
|
||||
|
||||
>[Google ScaNN](https://github.com/google-research/google-research/tree/master/scann)
|
||||
@@ -846,7 +613,7 @@ from langchain_community.vectorstores import ScaNN
|
||||
We need to install several python packages.
|
||||
|
||||
```bash
|
||||
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive
|
||||
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
|
||||
```
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/retrievers/google_drive).
|
||||
@@ -860,38 +627,16 @@ from langchain_googledrive.retrievers import GoogleDriveRetriever
|
||||
> [Vertex AI Search](https://cloud.google.com/generative-ai-app-builder/docs/introduction)
|
||||
> from Google Cloud allows developers to quickly build generative AI powered search engines for customers and employees.
|
||||
|
||||
See a [usage example](/docs/integrations/retrievers/google_vertex_ai_search).
|
||||
|
||||
Note: `GoogleVertexAISearchRetriever` is deprecated, use `VertexAIMultiTurnSearchRetriever`,
|
||||
`VertexAISearchSummaryTool`, and `VertexAISearchRetriever` (see below).
|
||||
|
||||
#### GoogleVertexAISearchRetriever
|
||||
|
||||
We need to install the `google-cloud-discoveryengine` python package.
|
||||
|
||||
```bash
|
||||
pip install google-cloud-discoveryengine
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_community.retrievers import GoogleVertexAISearchRetriever
|
||||
```
|
||||
|
||||
#### VertexAIMultiTurnSearchRetriever
|
||||
See a [usage example](/docs/integrations/retrievers/google_vertex_ai_search).
|
||||
|
||||
```python
|
||||
from langchain_google_community import VertexAIMultiTurnSearchRetriever
|
||||
```
|
||||
#### VertexAISearchRetriever
|
||||
|
||||
```python
|
||||
from langchain_google_community import VertexAIMultiTurnSearchRetriever
|
||||
```
|
||||
|
||||
#### VertexAISearchSummaryTool
|
||||
|
||||
```python
|
||||
from langchain_google_community import VertexAISearchSummaryTool
|
||||
from langchain.retrievers import GoogleVertexAISearchRetriever
|
||||
```
|
||||
|
||||
### Document AI Warehouse
|
||||
@@ -925,10 +670,10 @@ from langchain_google_community.documentai_warehouse import DocumentAIWarehouseR
|
||||
> It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks
|
||||
> to deliver the highest fidelity possible.
|
||||
|
||||
We need to install python packages.
|
||||
We need to install a python package.
|
||||
|
||||
```bash
|
||||
pip install google-cloud-text-to-speech langchain-google-community
|
||||
pip install google-cloud-text-to-speech
|
||||
```
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/tools/google_cloud_texttospeech).
|
||||
@@ -943,14 +688,13 @@ We need to install several python packages.
|
||||
|
||||
```bash
|
||||
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
|
||||
pip install langchain-googledrive
|
||||
```
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/tools/google_drive).
|
||||
|
||||
```python
|
||||
from langchain_googledrive.utilities.google_drive import GoogleDriveAPIWrapper
|
||||
from langchain_googledrive.tools.google_drive.tool import GoogleDriveSearchTool
|
||||
from langchain_community.utilities.google_drive import GoogleDriveAPIWrapper
|
||||
from langchain_community.tools.google_drive.tool import GoogleDriveSearchTool
|
||||
```
|
||||
|
||||
### Google Finance
|
||||
@@ -1040,23 +784,6 @@ from langchain.agents import load_tools
|
||||
tools = load_tools(["google-search"])
|
||||
```
|
||||
|
||||
#### GoogleSearchResults
|
||||
|
||||
Tool that queries the `Google Search` API (via `GoogleSearchAPIWrapper`) and gets back JSON.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GoogleSearchResults
|
||||
```
|
||||
|
||||
#### GoogleSearchRun
|
||||
|
||||
Tool that queries the `Google Search` API (via `GoogleSearchAPIWrapper`).
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GoogleSearchRun
|
||||
```
|
||||
|
||||
|
||||
### Google Trends
|
||||
|
||||
We need to install a python package.
|
||||
@@ -1091,18 +818,6 @@ See a [usage example and authorization instructions](/docs/integrations/tools/gm
|
||||
from langchain_google_community import GmailToolkit
|
||||
```
|
||||
|
||||
#### GMail individual tools
|
||||
|
||||
You can use individual tools from GMail Toolkit.
|
||||
|
||||
```python
|
||||
from langchain_google_community.gmail.create_draft import GmailCreateDraft
|
||||
from langchain_google_community.gmail.get_message import GmailGetMessage
|
||||
from langchain_google_community.gmail.get_thread import GmailGetThread
|
||||
from langchain_google_community.gmail.search import GmailSearch
|
||||
from langchain_google_community.gmail.send_message import GmailSendMessage
|
||||
```
|
||||
|
||||
## Memory
|
||||
|
||||
### AlloyDB for PostgreSQL
|
||||
@@ -1124,7 +839,6 @@ from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBChatMessageHistory
|
||||
### Cloud SQL for PostgreSQL
|
||||
|
||||
> [Cloud SQL for PostgreSQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1141,7 +855,6 @@ from langchain_google_cloud_sql_pg import PostgresEngine, PostgresChatMessageHis
|
||||
### Cloud SQL for MySQL
|
||||
|
||||
> [Cloud SQL for MySQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1157,7 +870,6 @@ from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLChatMessageHistor
|
||||
### Cloud SQL for SQL Server
|
||||
|
||||
> [Cloud SQL for SQL Server](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your SQL Server databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1173,7 +885,6 @@ from langchain_google_cloud_sql_mssql import MSSQLEngine, MSSQLChatMessageHistor
|
||||
### Spanner
|
||||
|
||||
> [Google Cloud Spanner](https://cloud.google.com/spanner/docs) is a fully managed, mission-critical, relational database service on Google Cloud that offers transactional consistency at global scale, automatic, synchronous replication for high availability, and support for two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1189,7 +900,6 @@ from langchain_google_spanner import SpannerChatMessageHistory
|
||||
### Memorystore for Redis
|
||||
|
||||
> [Google Cloud Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis) is a fully managed Redis service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Redis service without the burden of managing complex Redis deployments.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1205,7 +915,6 @@ from langchain_google_memorystore_redis import MemorystoreChatMessageHistory
|
||||
### Bigtable
|
||||
|
||||
> [Google Cloud Bigtable](https://cloud.google.com/bigtable/docs) is Google's fully managed NoSQL Big Data database service in Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1221,7 +930,6 @@ from langchain_google_bigtable import BigtableChatMessageHistory
|
||||
### Firestore (Native Mode)
|
||||
|
||||
> [Google Cloud Firestore](https://cloud.google.com/firestore/docs/) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1238,7 +946,6 @@ from langchain_google_firestore import FirestoreChatMessageHistory
|
||||
|
||||
> [Google Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
> Firestore is the newest version of Datastore and introduces several improvements over Datastore.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -1267,22 +974,6 @@ See [usage example](/docs/integrations/memory/google_el_carro).
|
||||
from langchain_google_el_carro import ElCarroChatMessageHistory
|
||||
```
|
||||
|
||||
## Callbacks
|
||||
|
||||
### Vertex AI callback handler
|
||||
|
||||
>Callback Handler that tracks `VertexAI` info.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.callbacks import VertexAICallbackHandler
|
||||
```
|
||||
|
||||
## Chat Loaders
|
||||
|
||||
### GMail
|
||||
@@ -1302,30 +993,6 @@ See a [usage example and authorization instructions](/docs/integrations/chat_loa
|
||||
from langchain_google_community import GMailLoader
|
||||
```
|
||||
|
||||
## Evaluators
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
### VertexPairWiseStringEvaluator
|
||||
|
||||
>Pair-wise evaluation of the perplexity of a predicted string.
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator
|
||||
```
|
||||
|
||||
### VertexStringEvaluator
|
||||
|
||||
>Evaluate the perplexity of a predicted string.
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator
|
||||
```
|
||||
|
||||
## 3rd Party Integrations
|
||||
|
||||
### SearchApi
|
||||
|
||||
@@ -12,7 +12,7 @@ pip install langchain-huggingface
|
||||
|
||||
## Chat models
|
||||
|
||||
### ChatHuggingFace
|
||||
### Models from Hugging Face
|
||||
|
||||
We can use the `Hugging Face` LLM classes or directly use the `ChatHuggingFace` class.
|
||||
|
||||
@@ -24,16 +24,7 @@ from langchain_huggingface import ChatHuggingFace
|
||||
|
||||
## LLMs
|
||||
|
||||
### HuggingFaceEndpoint
|
||||
|
||||
|
||||
See a [usage example](/docs/integrations/llms/huggingface_endpoint).
|
||||
|
||||
```python
|
||||
from langchain_huggingface import HuggingFaceEndpoint
|
||||
```
|
||||
|
||||
### HuggingFacePipeline
|
||||
### Hugging Face Local Pipelines
|
||||
|
||||
Hugging Face models can be run locally through the `HuggingFacePipeline` class.
|
||||
|
||||
@@ -53,22 +44,6 @@ See a [usage example](/docs/integrations/text_embedding/huggingfacehub).
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
```
|
||||
|
||||
### HuggingFaceEndpointEmbeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/huggingfacehub).
|
||||
|
||||
```python
|
||||
from langchain_huggingface import HuggingFaceEndpointEmbeddings
|
||||
```
|
||||
|
||||
### HuggingFaceInferenceAPIEmbeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/huggingfacehub).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
|
||||
```
|
||||
|
||||
### HuggingFaceInstructEmbeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/instruct_embeddings).
|
||||
@@ -79,7 +54,7 @@ from langchain_community.embeddings import HuggingFaceInstructEmbeddings
|
||||
|
||||
### HuggingFaceBgeEmbeddings
|
||||
|
||||
>[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en-v1.5) are one of [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).
|
||||
>[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en) are [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).
|
||||
>BGE model is created by the [Beijing Academy of Artificial Intelligence (BAAI)](https://en.wikipedia.org/wiki/Beijing_Academy_of_Artificial_Intelligence). `BAAI` is a private non-profit organization engaged in AI research and development.
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/bge_huggingface).
|
||||
@@ -88,14 +63,33 @@ See a [usage example](/docs/integrations/text_embedding/bge_huggingface).
|
||||
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
||||
```
|
||||
|
||||
### Hugging Face Text Embeddings Inference (TEI)
|
||||
|
||||
>[Hugging Face Text Embeddings Inference (TEI)](https://huggingface.co/docs/text-generation-inference/index) is a toolkit for deploying and serving open-source
|
||||
> text embeddings and sequence classification models. `TEI` enables high-performance extraction for the most popular models,
|
||||
>including `FlagEmbedding`, `Ember`, `GTE` and `E5`.
|
||||
|
||||
We need to install `huggingface-hub` python package.
|
||||
|
||||
```bash
|
||||
pip install huggingface-hub
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/text_embeddings_inference).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import HuggingFaceHubEmbeddings
|
||||
```
|
||||
|
||||
|
||||
## Document Loaders
|
||||
|
||||
### Hugging Face dataset
|
||||
|
||||
>[Hugging Face Hub](https://huggingface.co/docs/hub/index) is home to over 75,000
|
||||
> [datasets](https://huggingface.co/docs/hub/index#datasets) in more than 100 languages
|
||||
>[Hugging Face Hub](https://huggingface.co/docs/hub/index) is home to over 75,000
|
||||
> [datasets](https://huggingface.co/docs/hub/index#datasets) in more than 100 languages
|
||||
> that can be used for a broad range of tasks across NLP, Computer Vision, and Audio.
|
||||
> They used for a diverse range of tasks such as translation, automatic speech
|
||||
> They used for a diverse range of tasks such as translation, automatic speech
|
||||
> recognition, and image classification.
|
||||
|
||||
We need to install `datasets` python package.
|
||||
@@ -110,40 +104,13 @@ See a [usage example](/docs/integrations/document_loaders/hugging_face_dataset).
|
||||
from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader
|
||||
```
|
||||
|
||||
### Hugging Face model loader
|
||||
|
||||
>Load model information from `Hugging Face Hub`, including README content.
|
||||
>
|
||||
>This loader interfaces with the `Hugging Face Models API` to fetch
|
||||
> and load model metadata and README files.
|
||||
> The API allows you to search and filter models based on
|
||||
> specific criteria such as model tags, authors, and more.
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import HuggingFaceModelLoader
|
||||
```
|
||||
|
||||
### Image captions
|
||||
|
||||
It uses the Hugging Face models to generate image captions.
|
||||
|
||||
We need to install several python packages.
|
||||
|
||||
```bash
|
||||
pip install transformers pillow
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/document_loaders/image_captions).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import ImageCaptionLoader
|
||||
```
|
||||
|
||||
## Tools
|
||||
|
||||
### Hugging Face Hub Tools
|
||||
|
||||
>[Hugging Face Tools](https://huggingface.co/docs/transformers/v4.29.0/en/custom_tools)
|
||||
>[Hugging Face Tools](https://huggingface.co/docs/transformers/v4.29.0/en/custom_tools)
|
||||
> support text I/O and are loaded using the `load_huggingface_tool` function.
|
||||
|
||||
We need to install several python packages.
|
||||
@@ -157,12 +124,3 @@ See a [usage example](/docs/integrations/tools/huggingface_tools).
|
||||
```python
|
||||
from langchain_community.agent_toolkits.load_tools import load_huggingface_tool
|
||||
```
|
||||
|
||||
### Hugging Face Text-to-Speech Model Inference.
|
||||
|
||||
> It is a wrapper around `OpenAI Text-to-Speech API`.
|
||||
|
||||
```python
|
||||
from langchain_community.tools.audio import HuggingFaceTextToSpeechModelInference
|
||||
```
|
||||
|
||||
|
||||
@@ -436,8 +436,6 @@ See a [usage example](/docs/integrations/tools/azure_ai_services).
|
||||
from langchain_community.agent_toolkits import azure_ai_services
|
||||
```
|
||||
|
||||
#### Azure AI Services individual tools
|
||||
|
||||
The `azure_ai_services` toolkit includes the following tools:
|
||||
|
||||
- Image Analysis: [AzureAiServicesImageAnalysisTool](https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.azure_ai_services.image_analysis.AzureAiServicesImageAnalysisTool.html)
|
||||
@@ -462,23 +460,6 @@ See a [usage example](/docs/integrations/tools/office365).
|
||||
from langchain_community.agent_toolkits import O365Toolkit
|
||||
```
|
||||
|
||||
#### Office 365 individual tools
|
||||
|
||||
You can use individual tools from the Office 365 Toolkit:
|
||||
- `O365CreateDraftMessage`: tool for creating a draft email in Office 365
|
||||
- `O365SearchEmails`: tool for searching email messages in Office 365
|
||||
- `O365SearchEvents`: tool for searching calendar events in Office 365
|
||||
- `O365SendEvent`: tool for sending calendar events in Office 365
|
||||
- `O365SendMessage`: tool for sending an email in Office 365
|
||||
|
||||
```python
|
||||
from langchain_community.tools.office365 import O365CreateDraftMessage
|
||||
from langchain_community.tools.office365 import O365SearchEmails
|
||||
from langchain_community.tools.office365 import O365SearchEvents
|
||||
from langchain_community.tools.office365 import O365SendEvent
|
||||
from langchain_community.tools.office365 import O365SendMessage
|
||||
```
|
||||
|
||||
### Microsoft Azure PowerBI
|
||||
|
||||
We need to install `azure-identity` python package.
|
||||
@@ -494,20 +475,6 @@ from langchain_community.agent_toolkits import PowerBIToolkit
|
||||
from langchain_community.utilities.powerbi import PowerBIDataset
|
||||
```
|
||||
|
||||
#### PowerBI individual tools
|
||||
|
||||
You can use individual tools from the Azure PowerBI Toolkit:
|
||||
- `InfoPowerBITool`: tool for getting metadata about a PowerBI Dataset
|
||||
- `ListPowerBITool`: tool for getting tables names
|
||||
- `QueryPowerBITool`: tool for querying a PowerBI Dataset
|
||||
|
||||
```python
|
||||
from langchain_community.tools.powerbi.tool import InfoPowerBITool
|
||||
from langchain_community.tools.powerbi.tool import ListPowerBITool
|
||||
from langchain_community.tools.powerbi.tool import QueryPowerBITool
|
||||
```
|
||||
|
||||
|
||||
### PlayWright Browser Toolkit
|
||||
|
||||
>[Playwright](https://github.com/microsoft/playwright) is an open-source automation tool
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
# Apache Software Foundation
|
||||
|
||||
>[The Apache Software Foundation (Wikipedia)](https://en.wikipedia.org/wiki/The_Apache_Software_Foundation)
|
||||
> is a decentralized open source community of developers. The software they
|
||||
> produce is distributed under the terms of the Apache License, a permissive
|
||||
> open-source license for free and open-source software (FOSS). The Apache projects
|
||||
> are characterized by a collaborative, consensus-based development process
|
||||
> and an open and pragmatic software license, which is to say that it
|
||||
> allows developers, who receive the software freely, to redistribute
|
||||
> it under non-free terms. Each project is managed by a self-selected
|
||||
> team of technical experts who are active contributors to the project.
|
||||
|
||||
## Apache AGE
|
||||
|
||||
>[Apache AGE](https://age.apache.org/) is a `PostgreSQL` extension that provides
|
||||
> graph database functionality. `AGE` is an acronym for `A Graph Extension`, and
|
||||
> is inspired by Bitnine’s fork of `PostgreSQL 10`, `AgensGraph`, which is
|
||||
> a multimodal database. The goal of the project is to create single
|
||||
> storage that can handle both relational and graph model data so that users
|
||||
> can use standard ANSI SQL along with `openCypher`, the Graph query language.
|
||||
> The data elements `Apache AGE` stores are nodes, edges connecting them, and
|
||||
> attributes of nodes and edges.
|
||||
|
||||
See more about [integrating with Apache AGE](/docs/integrations/graphs/apache_age).
|
||||
|
||||
## Apache Cassandra
|
||||
|
||||
>[Apache Cassandra](https://cassandra.apache.org/) is a NoSQL, row-oriented,
|
||||
> highly scalable and highly available database. Starting with version 5.0,
|
||||
> the database ships with vector search capabilities.
|
||||
|
||||
See more about [integrating with Apache Cassandra](/docs/integrations/providers/cassandra/).
|
||||
|
||||
## Apache Doris
|
||||
|
||||
>[Apache Doris](https://doris.apache.org/) is a modern data warehouse for
|
||||
> real-time analytics. It delivers lightning-fast analytics on real-time data at scale.
|
||||
>
|
||||
>Usually `Apache Doris` is categorized into OLAP, and it has showed excellent
|
||||
> performance in ClickBench — a Benchmark For Analytical DBMS. Since it has
|
||||
> a super-fast vectorized execution engine, it could also be used as a fast vectordb.
|
||||
|
||||
See more about [integrating with Apache Doris](/docs/integrations/providers/apache_doris/).
|
||||
|
||||
## Apache Kafka
|
||||
|
||||
>[Apache Kafka](https://github.com/apache/kafka) is a distributed messaging system
|
||||
> that is used to publish and subscribe to streams of records.
|
||||
|
||||
See more about [integrating with Apache Kafka](/docs/integrations/memory/kafka_chat_message_history).
|
||||
|
||||
|
||||
## Apache Spark
|
||||
|
||||
>[Apache Spark](https://spark.apache.org/) is a unified analytics engine for
|
||||
> large-scale data processing. It provides high-level APIs in Scala, Java,
|
||||
> Python, and R, and an optimized engine that supports general computation
|
||||
> graphs for data analysis. It also supports a rich set of higher-level
|
||||
> tools including `Spark SQL` for SQL and DataFrames, `pandas API on Spark`
|
||||
> for pandas workloads, `MLlib` for machine learning,
|
||||
> `GraphX` for graph processing, and `Structured Streaming` for stream processing.
|
||||
|
||||
See more about [integrating with Apache Spark](/docs/integrations/providers/spark).
|
||||
@@ -1,22 +0,0 @@
|
||||
# Apple
|
||||
|
||||
>[Apple Inc. (Wikipedia)](https://en.wikipedia.org/wiki/Apple_Inc.) is an American
|
||||
> multinational corporation and technology company.
|
||||
>
|
||||
> [iMessage (Wikipedia)](https://en.wikipedia.org/wiki/IMessage) is an instant
|
||||
> messaging service developed by Apple Inc. and launched in 2011.
|
||||
> `iMessage` functions exclusively on Apple platforms.
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
See [setup instructions](/docs/integrations/chat_loaders/imessage).
|
||||
|
||||
## Chat loader
|
||||
|
||||
It loads chat sessions from the `iMessage` `chat.db` `SQLite` file.
|
||||
|
||||
See a [usage example](/docs/integrations/chat_loaders/imessage).
|
||||
|
||||
```python
|
||||
from langchain_community.chat_loaders.imessage import IMessageChatLoader
|
||||
```
|
||||
@@ -24,7 +24,6 @@ from langchain_community.llms import QianfanLLMEndpoint
|
||||
### Qianfan Chat Endpoint
|
||||
|
||||
See a [usage example](/docs/integrations/chat/baidu_qianfan_endpoint).
|
||||
See another [usage example](/docs/integrations/chat/ernie).
|
||||
|
||||
```python
|
||||
from langchain_community.chat_models import QianfanChatEndpoint
|
||||
@@ -35,7 +34,6 @@ from langchain_community.chat_models import QianfanChatEndpoint
|
||||
### Baidu Qianfan
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/baidu_qianfan_endpoint).
|
||||
See another [usage example](/docs/integrations/text_embedding/ernie).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import QianfanEmbeddingsEndpoint
|
||||
|
||||
@@ -83,28 +83,3 @@ from langchain_community.agent_toolkits.cassandra_database.toolkit import (
|
||||
Learn more in the [example notebook](/docs/integrations/tools/cassandra_database).
|
||||
|
||||
|
||||
Cassandra Database individual tools:
|
||||
|
||||
### Get Schema
|
||||
|
||||
Tool for getting the schema of a keyspace in an Apache Cassandra database.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GetSchemaCassandraDatabaseTool
|
||||
```
|
||||
|
||||
### Get Table Data
|
||||
|
||||
Tool for getting data from a table in an Apache Cassandra database.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GetTableDataCassandraDatabaseTool
|
||||
```
|
||||
|
||||
### Query
|
||||
|
||||
Tool for querying an Apache Cassandra database with provided CQL.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import QueryCassandraDatabaseTool
|
||||
```
|
||||
|
||||
@@ -11,22 +11,13 @@ Databricks embraces the LangChain ecosystem in various ways:
|
||||
4. 🌐 **SQL Database** - [Databricks SQL](https://www.databricks.com/product/databricks-sql) is integrated with `SQLDatabase` in LangChain, allowing you to access the auto-optimizing, exceptionally performant data warehouse.
|
||||
5. 💡 **Open Models** - Databricks open sources models, such as [DBRX](https://www.databricks.com/blog/introducing-dbrx-new-state-art-open-llm), which are available through the [Hugging Face Hub](https://huggingface.co/databricks/dbrx-instruct). These models can be directly utilized with LangChain, leveraging its integration with the `transformers` library.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First-party Databricks integrations are available in the langchain-databricks partner package.
|
||||
|
||||
```
|
||||
pip install langchain-databricks
|
||||
```
|
||||
|
||||
Chat Model
|
||||
----------
|
||||
|
||||
`ChatDatabricks` is a Chat Model class to access chat endpoints hosted on Databricks, including state-of-the-art models such as Llama3, Mixtral, and DBRX, as well as your own fine-tuned models.
|
||||
|
||||
```
|
||||
from langchain_databricks import ChatDatabricks
|
||||
from langchain_community.chat_models.databricks import ChatDatabricks
|
||||
|
||||
chat_model = ChatDatabricks(endpoint="databricks-meta-llama-3-70b-instruct")
|
||||
```
|
||||
@@ -38,10 +29,6 @@ LLM
|
||||
|
||||
`Databricks` is an LLM class to access completion endpoints hosted on Databricks.
|
||||
|
||||
:::caution
|
||||
Text completion models have been deprecated and the latest and most popular models are [chat completion models](/docs/concepts/#chat-models). Use `ChatDatabricks` chat model instead to use those models and advanced features such as tool calling.
|
||||
:::
|
||||
|
||||
```
|
||||
from langchain_community.llm.databricks import Databricks
|
||||
|
||||
@@ -57,7 +44,7 @@ Embeddings
|
||||
`DatabricksEmbeddings` is an Embeddings class to access text-embedding endpoints hosted on Databricks, including state-of-the-art models such as BGE, as well as your own fine-tuned models.
|
||||
|
||||
```
|
||||
from langchain_databricks import DatabricksEmbeddings
|
||||
from langchain_community.embeddings import DatabricksEmbeddings
|
||||
|
||||
embeddings = DatabricksEmbeddings(endpoint="databricks-bge-large-en")
|
||||
```
|
||||
@@ -71,15 +58,10 @@ Vector Search
|
||||
Databricks Vector Search is a serverless similarity search engine that allows you to store a vector representation of your data, including metadata, in a vector database. With Vector Search, you can create auto-updating vector search indexes from [Delta](https://docs.databricks.com/en/introduction/delta-comparison.html) tables managed by [Unity Catalog](https://www.databricks.com/product/unity-catalog) and query them with a simple API to return the most similar vectors.
|
||||
|
||||
```
|
||||
from langchain_databricks.vectorstores import DatabricksVectorSearch
|
||||
from langchain_community.vectorstores import DatabricksVectorSearch
|
||||
|
||||
dvs = DatabricksVectorSearch(
|
||||
endpoint="<YOUT_ENDPOINT_NAME>",
|
||||
index_name="<YOUR_INDEX_NAME>",
|
||||
index,
|
||||
text_column="text",
|
||||
embedding=embeddings,
|
||||
columns=["source"]
|
||||
index, text_column="text", embedding=embeddings, columns=["source"]
|
||||
)
|
||||
docs = dvs.similarity_search("What is vector search?)
|
||||
```
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# Embedchain
|
||||
|
||||
> [Embedchain](https://github.com/embedchain/embedchain) is a RAG framework to create
|
||||
> data pipelines. It loads, indexes, retrieves and syncs all the data.
|
||||
>
|
||||
>It is available as an [open source package](https://github.com/embedchain/embedchain)
|
||||
> and as a [hosted platform solution](https://app.embedchain.ai/).
|
||||
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
Install the package using pip:
|
||||
|
||||
```bash
|
||||
pip install embedchain
|
||||
```
|
||||
|
||||
|
||||
## Retriever
|
||||
|
||||
See a [usage example](/docs/integrations/retrievers/embedchain).
|
||||
|
||||
```python
|
||||
from langchain_community.retrievers import EmbedchainRetriever
|
||||
```
|
||||
@@ -4,14 +4,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exa\n",
|
||||
"# Exa Search\n",
|
||||
"\n",
|
||||
">[Exa](https://exa.ai/) is a knowledge API for AI and developers.\n",
|
||||
">\n",
|
||||
"\n",
|
||||
"## Installation and Setup\n",
|
||||
"\n",
|
||||
"`Exa` integration exists in its own [partner package](https://pypi.org/project/langchain-exa/). You can install it with:"
|
||||
"Exa's search integration exists in its own [partner package](https://pypi.org/project/langchain-exa/). You can install it with:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -31,9 +26,7 @@
|
||||
"\n",
|
||||
"## Retriever\n",
|
||||
"\n",
|
||||
"You can use the [`ExaSearchRetriever`](/docs/integrations/tools/exa_search#using-exasearchretriever) in a standard retrieval pipeline. You can import it as follows.\n",
|
||||
"\n",
|
||||
"See a [usage example](/docs/integrations/tools/exa_search).\n"
|
||||
"You can use the [`ExaSearchRetriever`](/docs/integrations/tools/exa_search#using-exasearchretriever) in a standard retrieval pipeline. You can import it as follows"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -53,40 +46,7 @@
|
||||
"source": [
|
||||
"## Tools\n",
|
||||
"\n",
|
||||
"You can use Exa as an agent tool as described in the [Exa tool calling docs](/docs/integrations/tools/exa_search#using-the-exa-sdk-as-langchain-agent-tools).\n",
|
||||
"\n",
|
||||
"See a [usage example](/docs/integrations/tools/exa_search).\n",
|
||||
"\n",
|
||||
"### ExaFindSimilarResults\n",
|
||||
"\n",
|
||||
"A tool that queries the Metaphor Search API and gets back JSON."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_exa.tools import ExaFindSimilarResults"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### ExaSearchResults\n",
|
||||
"\n",
|
||||
"Exa Search tool."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_exa.tools import ExaSearchResults"
|
||||
"You can use Exa as an agent tool as described in the [Exa tool calling docs](/docs/integrations/tools/exa_search#using-the-exa-sdk-as-langchain-agent-tools).\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -109,9 +69,9 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
"version": "3.10.11"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# FalkorDB
|
||||
|
||||
>[FalkorDB](https://www.falkordb.com/) is a creator of the [FalkorDB](https://docs.falkordb.com/),
|
||||
> a low-latency Graph Database that delivers knowledge to GenAI.
|
||||
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
See [installation instructions here](/docs/integrations/graphs/falkordb/).
|
||||
|
||||
|
||||
## Graphs
|
||||
|
||||
See a [usage example](/docs/integrations/graphs/falkordb).
|
||||
|
||||
```python
|
||||
from langchain_community.graphs import FalkorDBGraph
|
||||
```
|
||||
|
||||
## Chains
|
||||
|
||||
See a [usage example](/docs/integrations/graphs/falkordb).
|
||||
|
||||
```python
|
||||
from langchain_community.chains.graph_qa.falkordb import FalkorDBQAChain
|
||||
```
|
||||
@@ -1,22 +0,0 @@
|
||||
# FireCrawl
|
||||
|
||||
>[FireCrawl](https://firecrawl.dev/?ref=langchain) crawls and converts any website into LLM-ready data.
|
||||
> It crawls all accessible subpages and give you clean markdown
|
||||
> and metadata for each. No sitemap required.
|
||||
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
Install the python SDK:
|
||||
|
||||
```bash
|
||||
pip install firecrawl-py
|
||||
```
|
||||
|
||||
## Document loader
|
||||
|
||||
See a [usage example](/docs/integrations/document_loaders/firecrawl).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import FireCrawlLoader
|
||||
```
|
||||
@@ -1,32 +0,0 @@
|
||||
# Friendli AI
|
||||
|
||||
>[Friendli AI](https://friendli.ai/) is a company that fine-tunes, deploys LLMs,
|
||||
> and serves a wide range of Generative AI use cases.
|
||||
|
||||
|
||||
## Installation and setup
|
||||
|
||||
- Install the integration package:
|
||||
|
||||
```
|
||||
pip install friendli-client
|
||||
```
|
||||
|
||||
- Sign in to [Friendli Suite](https://suite.friendli.ai/) to create a Personal Access Token,
|
||||
and set it as the `FRIENDLI_TOKEN` environment.
|
||||
|
||||
## Chat models
|
||||
|
||||
See a [usage example](/docs/integrations/chat/friendli).
|
||||
|
||||
```python
|
||||
from langchain_community.chat_models.friendli import ChatFriendli
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
See a [usage example](/docs/integrations/llms/friendli).
|
||||
|
||||
```python
|
||||
from langchain_community.llms.friendli import Friendli
|
||||
```
|
||||
@@ -20,26 +20,3 @@ See a [usage example](/docs/integrations/document_loaders/github).
|
||||
```python
|
||||
from langchain_community.document_loaders import GitHubIssuesLoader, GithubFileLoader
|
||||
```
|
||||
|
||||
## Tools/Toolkit
|
||||
|
||||
### GitHubToolkit
|
||||
The `GitHub` toolkit contains tools that enable an LLM agent to interact
|
||||
with a GitHub repository.
|
||||
|
||||
The toolkit is a wrapper for the `PyGitHub` library.
|
||||
|
||||
```python
|
||||
from langchain_community.agent_toolkits.github.toolkit import GitHubToolkit
|
||||
```
|
||||
|
||||
Learn more in the [example notebook](/docs/integrations/tools/github).
|
||||
|
||||
### GitHubAction
|
||||
|
||||
Tool for interacting with the GitHub API.
|
||||
|
||||
```python
|
||||
from langchain_community.tools.github.tool import GitHubAction
|
||||
```
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# GitLab
|
||||
|
||||
>[GitLab Inc.](https://about.gitlab.com/) is an open-core company
|
||||
> that operates `GitLab`, a DevOps software package that can develop,
|
||||
> secure, and operate software. `GitLab` includes a distributed version
|
||||
> control based on Git, including features such as access control, bug tracking,
|
||||
> software feature requests, task management, and wikis for every project,
|
||||
> as well as snippets.
|
||||
|
||||
|
||||
## Tools/Toolkits
|
||||
|
||||
### GitLabToolkit
|
||||
|
||||
The `Gitlab` toolkit contains tools that enable an LLM agent to interact with a gitlab repository.
|
||||
|
||||
The toolkit is a wrapper for the `python-gitlab` library.
|
||||
|
||||
See a [usage example](/docs/integrations/tools/gitlab).
|
||||
|
||||
```python
|
||||
from langchain_community.agent_toolkits.gitlab.toolkit import GitLabToolkit
|
||||
```
|
||||
|
||||
### GitLabAction
|
||||
|
||||
Tool for interacting with the GitLab API.
|
||||
|
||||
```python
|
||||
from langchain_community.tools.github.tool import GitHubAction
|
||||
```
|
||||
69
docs/docs/integrations/providers/nomic.ipynb
Normal file
69
docs/docs/integrations/providers/nomic.ipynb
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Nomic\n",
|
||||
"\n",
|
||||
"Nomic currently offers two products:\n",
|
||||
"\n",
|
||||
"- Atlas: their Visual Data Engine\n",
|
||||
"- GPT4All: their Open Source Edge Language Model Ecosystem\n",
|
||||
"\n",
|
||||
"The Nomic integration exists in its own [partner package](https://pypi.org/project/langchain-nomic/). You can install it with:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -qU langchain-nomic"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Currently, you can import their hosted [embedding model](/docs/integrations/text_embedding/nomic) as follows:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"id": "y8ku6X96sebl"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_nomic import NomicEmbeddings"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.11"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
# Nomic
|
||||
|
||||
>[Nomic](https://www.nomic.ai/) builds tools that enable everyone to interact with AI scale datasets and run AI models on consumer computers.
|
||||
>
|
||||
>`Nomic` currently offers two products:
|
||||
>
|
||||
>- `Atlas`: the Visual Data Engine
|
||||
>- `GPT4All`: the Open Source Edge Language Model Ecosystem
|
||||
|
||||
The Nomic integration exists in two partner packages: [langchain-nomic](https://pypi.org/project/langchain-nomic/)
|
||||
and in [langchain-community](https://pypi.org/project/langchain-community/).
|
||||
|
||||
## Installation
|
||||
|
||||
You can install them with:
|
||||
|
||||
```bash
|
||||
pip install -U langchain-nomic
|
||||
pip install -U langchain-community
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
### GPT4All
|
||||
|
||||
See [a usage example](/docs/integrations/llms/gpt4all).
|
||||
|
||||
```python
|
||||
from langchain_community.llms import GPT4All
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### NomicEmbeddings
|
||||
|
||||
See [a usage example](/docs/integrations/text_embedding/nomic).
|
||||
|
||||
```python
|
||||
from langchain_nomic import NomicEmbeddings
|
||||
```
|
||||
|
||||
### GPT4All
|
||||
|
||||
See [a usage example](/docs/integrations/text_embedding/gpt4all).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import GPT4AllEmbeddings
|
||||
```
|
||||
|
||||
## Vector store
|
||||
|
||||
### Atlas
|
||||
|
||||
See [a usage example and installation instructions](/docs/integrations/vectorstores/atlas).
|
||||
|
||||
```python
|
||||
from langchain_community.vectorstores import AtlasDB
|
||||
```
|
||||
@@ -21,24 +21,9 @@ model = Predibase(
|
||||
model="mistral-7b",
|
||||
predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),
|
||||
predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)
|
||||
"""
|
||||
Optionally use `model_kwargs` to set new default "generate()" settings. For example:
|
||||
{
|
||||
"api_token": os.environ.get("HUGGING_FACE_HUB_TOKEN"),
|
||||
"max_new_tokens": 5, # default is 256
|
||||
}
|
||||
"""
|
||||
**model_kwargs,
|
||||
)
|
||||
|
||||
"""
|
||||
Optionally use `kwargs` to dynamically overwrite "generate()" settings. For example:
|
||||
{
|
||||
"temperature": 0.5, # default is the value in model_kwargs or 0.1 (initialization default)
|
||||
"max_new_tokens": 1024, # default is the value in model_kwargs or 256 (initialization default)
|
||||
}
|
||||
"""
|
||||
response = model.invoke("Can you recommend me a nice dry wine?", **kwargs)
|
||||
response = model.invoke("Can you recommend me a nice dry wine?")
|
||||
print(response)
|
||||
```
|
||||
|
||||
@@ -57,24 +42,9 @@ model = Predibase(
|
||||
predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)
|
||||
adapter_id="e2e_nlg",
|
||||
adapter_version=1,
|
||||
"""
|
||||
Optionally use `model_kwargs` to set new default "generate()" settings. For example:
|
||||
{
|
||||
"api_token": os.environ.get("HUGGING_FACE_HUB_TOKEN"),
|
||||
"max_new_tokens": 5, # default is 256
|
||||
}
|
||||
"""
|
||||
**model_kwargs,
|
||||
)
|
||||
|
||||
"""
|
||||
Optionally use `kwargs` to dynamically overwrite "generate()" settings. For example:
|
||||
{
|
||||
"temperature": 0.5, # default is the value in model_kwargs or 0.1 (initialization default)
|
||||
"max_new_tokens": 1024, # default is the value in model_kwargs or 256 (initialization default)
|
||||
}
|
||||
"""
|
||||
response = model.invoke("Can you recommend me a nice dry wine?", **kwargs)
|
||||
response = model.invoke("Can you recommend me a nice dry wine?")
|
||||
print(response)
|
||||
```
|
||||
|
||||
@@ -92,23 +62,8 @@ model = Predibase(
|
||||
predibase_api_key=os.environ.get("PREDIBASE_API_TOKEN"),
|
||||
predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)
|
||||
adapter_id="predibase/e2e_nlg",
|
||||
"""
|
||||
Optionally use `model_kwargs` to set new default "generate()" settings. For example:
|
||||
{
|
||||
"api_token": os.environ.get("HUGGING_FACE_HUB_TOKEN"),
|
||||
"max_new_tokens": 5, # default is 256
|
||||
}
|
||||
"""
|
||||
**model_kwargs,
|
||||
)
|
||||
|
||||
"""
|
||||
Optionally use `kwargs` to dynamically overwrite "generate()" settings. For example:
|
||||
{
|
||||
"temperature": 0.5, # default is the value in model_kwargs or 0.1 (initialization default)
|
||||
"max_new_tokens": 1024, # default is the value in model_kwargs or 256 (initialization default)
|
||||
}
|
||||
"""
|
||||
response = model.invoke("Can you recommend me a nice dry wine?", **kwargs)
|
||||
response = model.invoke("Can you recommend me a nice dry wine?")
|
||||
print(response)
|
||||
```
|
||||
|
||||
@@ -13,19 +13,6 @@ Install the Python partner package:
|
||||
pip install langchain-qdrant
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### FastEmbedSparse
|
||||
|
||||
```python
|
||||
from langchain_qdrant import FastEmbedSparse
|
||||
```
|
||||
|
||||
### SparseEmbeddings
|
||||
|
||||
```python
|
||||
from langchain_qdrant import SparseEmbeddings
|
||||
```
|
||||
|
||||
## Vector Store
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
# Spark
|
||||
|
||||
>[Apache Spark](https://spark.apache.org/) is a unified analytics engine for
|
||||
> large-scale data processing. It provides high-level APIs in Scala, Java,
|
||||
> Python, and R, and an optimized engine that supports general computation
|
||||
> graphs for data analysis. It also supports a rich set of higher-level
|
||||
> tools including `Spark SQL` for SQL and DataFrames, `pandas API on Spark`
|
||||
> for pandas workloads, `MLlib` for machine learning,
|
||||
> `GraphX` for graph processing, and `Structured Streaming` for stream processing.
|
||||
|
||||
## Document loaders
|
||||
|
||||
### PySpark
|
||||
|
||||
It loads data from a `PySpark` DataFrame.
|
||||
|
||||
See a [usage example](/docs/integrations/document_loaders/pyspark_dataframe).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import PySparkDataFrameLoader
|
||||
```
|
||||
|
||||
## Tools/Toolkits
|
||||
|
||||
### Spark SQL toolkit
|
||||
|
||||
Toolkit for interacting with `Spark SQL`.
|
||||
|
||||
See a [usage example](/docs/integrations/tools/spark_sql).
|
||||
|
||||
```python
|
||||
from langchain_community.agent_toolkits import SparkSQLToolkit, create_spark_sql_agent
|
||||
from langchain_community.utilities.spark_sql import SparkSQL
|
||||
```
|
||||
|
||||
#### Spark SQL individual tools
|
||||
|
||||
You can use individual tools from the Spark SQL Toolkit:
|
||||
- `InfoSparkSQLTool`: tool for getting metadata about a Spark SQL
|
||||
- `ListSparkSQLTool`: tool for getting tables names
|
||||
- `QueryCheckerTool`: tool uses an LLM to check if a query is correct
|
||||
- `QuerySparkSQLTool`: tool for querying a Spark SQL
|
||||
|
||||
```python
|
||||
from langchain_community.tools.spark_sql.tool import InfoSparkSQLTool
|
||||
from langchain_community.tools.spark_sql.tool import ListSparkSQLTool
|
||||
from langchain_community.tools.spark_sql.tool import QueryCheckerTool
|
||||
from langchain_community.tools.spark_sql.tool import QuerySparkSQLTool
|
||||
```
|
||||
@@ -4,26 +4,11 @@
|
||||
It has cross-domain knowledge and language understanding ability by learning a large amount of texts, codes and images.
|
||||
It can understand and perform tasks based on natural dialogue.
|
||||
|
||||
## Chat models
|
||||
## SparkLLM LLM Model
|
||||
An example is available at [example](/docs/integrations/llms/sparkllm).
|
||||
|
||||
See a [usage example](/docs/integrations/chat/sparkllm).
|
||||
## SparkLLM Chat Model
|
||||
An example is available at [example](/docs/integrations/chat/sparkllm).
|
||||
|
||||
```python
|
||||
from langchain_community.chat_models import ChatSparkLLM
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
See a [usage example](/docs/integrations/llms/sparkllm).
|
||||
|
||||
```python
|
||||
from langchain_community.llms import SparkLLM
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/sparkllm)
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import SparkLLMTextEmbeddings
|
||||
```
|
||||
## SparkLLM Text Embedding Model
|
||||
An example is available at [example](/docs/integrations/text_embedding/sparkllm)
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
# Transwarp
|
||||
|
||||
>[Transwarp](https://www.transwarp.cn/en/introduction) aims to build
|
||||
> enterprise-level big data and AI infrastructure software,
|
||||
> to shape the future of data world. It provides enterprises with
|
||||
> infrastructure software and services around the whole data lifecycle,
|
||||
> including integration, storage, governance, modeling, analysis,
|
||||
> mining and circulation.
|
||||
>
|
||||
> `Transwarp` focuses on technology research and
|
||||
> development and has accumulated core technologies in these aspects:
|
||||
> distributed computing, SQL compilations, database technology,
|
||||
> unification for multi-model data management, container-based cloud computing,
|
||||
> and big data analytics and intelligence.
|
||||
|
||||
## Installation
|
||||
|
||||
You have to install several python packages:
|
||||
|
||||
```bash
|
||||
pip install -U tiktoken hippo-api
|
||||
```
|
||||
|
||||
and get the connection configuration.
|
||||
|
||||
## Vector stores
|
||||
|
||||
### Hippo
|
||||
|
||||
See [a usage example and installation instructions](/docs/integrations/vectorstores/hippo).
|
||||
|
||||
```python
|
||||
from langchain_community.vectorstores.hippo import Hippo
|
||||
```
|
||||
@@ -6,18 +6,45 @@
|
||||
"source": [
|
||||
"# Upstage\n",
|
||||
"\n",
|
||||
">[Upstage](https://upstage.ai) is a leading artificial intelligence (AI) company specializing in delivering above-human-grade performance LLM components.\n",
|
||||
">\n",
|
||||
">**Solar Mini Chat** is a fast yet powerful advanced large language model focusing on English and Korean. It has been specifically fine-tuned for multi-turn chat purposes, showing enhanced performance across a wide range of natural language processing tasks, like multi-turn conversation or tasks that require an understanding of long contexts, such as RAG (Retrieval-Augmented Generation), compared to other models of a similar size. This fine-tuning equips it with the ability to handle longer conversations more effectively, making it particularly adept for interactive applications.\n",
|
||||
"\n",
|
||||
">Other than Solar, Upstage also offers features for real-world RAG (retrieval-augmented generation), such as **Groundedness Check** and **Layout Analysis**. \n"
|
||||
"[Upstage](https://upstage.ai) is a leading artificial intelligence (AI) company specializing in delivering above-human-grade performance LLM components. \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Upstage LangChain integrations\n",
|
||||
"## Solar LLM\n",
|
||||
"\n",
|
||||
"**Solar Mini Chat** is a fast yet powerful advanced large language model focusing on English and Korean. It has been specifically fine-tuned for multi-turn chat purposes, showing enhanced performance across a wide range of natural language processing tasks, like multi-turn conversation or tasks that require an understanding of long contexts, such as RAG (Retrieval-Augmented Generation), compared to other models of a similar size. This fine-tuning equips it with the ability to handle longer conversations more effectively, making it particularly adept for interactive applications.\n",
|
||||
"\n",
|
||||
"Other than Solar, Upstage also offers features for real-world RAG (retrieval-augmented generation), such as **Groundedness Check** and **Layout Analysis**. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Installation and Setup\n",
|
||||
"\n",
|
||||
"Install `langchain-upstage` package:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install -qU langchain-core langchain-upstage\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Get [API Keys](https://console.upstage.ai) and set environment variable `UPSTAGE_API_KEY`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Upstage LangChain integrations\n",
|
||||
"\n",
|
||||
"| API | Description | Import | Example usage |\n",
|
||||
"| --- | --- | --- | --- |\n",
|
||||
@@ -33,20 +60,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Installation and Setup\n",
|
||||
"## Quick Examples\n",
|
||||
"\n",
|
||||
"Install `langchain-upstage` package:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install -qU langchain-core langchain-upstage\n",
|
||||
"```\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Get [API Keys](https://console.upstage.ai) and set environment variable `UPSTAGE_API_KEY`."
|
||||
"### Environment Setup"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -64,11 +80,8 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Chat models\n",
|
||||
"\n",
|
||||
"### Solar LLM\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/chat/upstage)."
|
||||
"### Chat\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -88,9 +101,10 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Embedding models\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/text_embedding/upstage)."
|
||||
"\n",
|
||||
"### Text embedding\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -120,45 +134,7 @@
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Document loader\n",
|
||||
"\n",
|
||||
"### Layout Analysis\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/document_loaders/upstage)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_upstage import UpstageLayoutAnalysisLoader\n",
|
||||
"\n",
|
||||
"file_path = \"/PATH/TO/YOUR/FILE.pdf\"\n",
|
||||
"layzer = UpstageLayoutAnalysisLoader(file_path, split=\"page\")\n",
|
||||
"\n",
|
||||
"# For improved memory efficiency, consider using the lazy_load method to load documents page by page.\n",
|
||||
"docs = layzer.load() # or layzer.lazy_load()\n",
|
||||
"\n",
|
||||
"for doc in docs[:3]:\n",
|
||||
" print(doc)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"jupyter": {
|
||||
"outputs_hidden": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Tools\n",
|
||||
"\n",
|
||||
"### Groundedness Check\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/tools/upstage_groundedness_check)."
|
||||
"### Groundedness Check"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -183,6 +159,36 @@
|
||||
"response = groundedness_check.invoke(request_input)\n",
|
||||
"print(response)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"jupyter": {
|
||||
"outputs_hidden": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Layout Analysis"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_upstage import UpstageLayoutAnalysisLoader\n",
|
||||
"\n",
|
||||
"file_path = \"/PATH/TO/YOUR/FILE.pdf\"\n",
|
||||
"layzer = UpstageLayoutAnalysisLoader(file_path, split=\"page\")\n",
|
||||
"\n",
|
||||
"# For improved memory efficiency, consider using the lazy_load method to load documents page by page.\n",
|
||||
"docs = layzer.load() # or layzer.lazy_load()\n",
|
||||
"\n",
|
||||
"for doc in docs[:3]:\n",
|
||||
" print(doc)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -204,7 +210,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
"version": "3.10.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -44,12 +44,11 @@ from langchain_community.vectorstores.vdms import VDMS_Client
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
client = VDMS_Client("localhost", 55555)
|
||||
model_name = "sentence-transformers/all-mpnet-base-v2"
|
||||
vectorstore = VDMS.from_documents(
|
||||
docs,
|
||||
client=client,
|
||||
collection_name="langchain-demo",
|
||||
embedding_function=HuggingFaceEmbeddings(model_name=model_name),
|
||||
embedding_function=HuggingFaceEmbeddings(),
|
||||
engine="FaissFlat"
|
||||
distance_strategy="L2",
|
||||
)
|
||||
@@ -59,3 +58,5 @@ results = vectorstore.similarity_search(query)
|
||||
```
|
||||
|
||||
For a more detailed walkthrough of the VDMS wrapper, see [this notebook](/docs/integrations/vectorstores/vdms)
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# Yahoo
|
||||
|
||||
>[Yahoo (Wikipedia)](https://en.wikipedia.org/wiki/Yahoo) is an American web services provider.
|
||||
>
|
||||
> It provides a web portal, search engine Yahoo Search, and related
|
||||
> services, including `My Yahoo`, `Yahoo Mail`, `Yahoo News`,
|
||||
> `Yahoo Finance`, `Yahoo Sports` and its advertising platform, `Yahoo Native`.
|
||||
|
||||
|
||||
## Tools
|
||||
|
||||
### Yahoo Finance News
|
||||
|
||||
We have to install a python package:
|
||||
|
||||
```bash
|
||||
pip install yfinance
|
||||
```
|
||||
See a [usage example](/docs/integrations/tools/yahoo_finance_news).
|
||||
|
||||
|
||||
```python
|
||||
from langchain_community.tools import YahooFinanceNewsTool
|
||||
```
|
||||
@@ -31,26 +31,3 @@ See a [usage example](/docs/integrations/chat/yandex).
|
||||
```python
|
||||
from langchain_community.chat_models import ChatYandexGPT
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### YandexGPT
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/yandex).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import YandexGPTEmbeddings
|
||||
```
|
||||
|
||||
## Parser
|
||||
|
||||
### YandexSTTParser
|
||||
|
||||
It transcribes and parses audio files.
|
||||
|
||||
`YandexSTTParser` is similar to the `OpenAIWhisperParser`.
|
||||
See a [usage example with OpenAIWhisperParser](/docs/integrations/document_loaders/youtube_audio).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import YandexSTTParser
|
||||
```
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# Yellowbrick
|
||||
|
||||
>[Yellowbrick](https://yellowbrick.com/) is a provider of
|
||||
> Enterprise Data Warehousing, Ad-hoc and Streaming Analytics,
|
||||
> BI and AI workloads.
|
||||
|
||||
## Vector store
|
||||
|
||||
We have to install a python package:
|
||||
|
||||
```bash
|
||||
pip install psycopg2
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_community.vectorstores import Yellowbrick
|
||||
```
|
||||
@@ -1,19 +0,0 @@
|
||||
# You
|
||||
|
||||
>[You](https://you.com/about) company provides an AI productivity platform.
|
||||
|
||||
## Retriever
|
||||
|
||||
See a [usage example](/docs/integrations/retrievers/you-retriever).
|
||||
|
||||
```python
|
||||
from langchain_community.retrievers.you import YouRetriever
|
||||
```
|
||||
|
||||
## Tools
|
||||
|
||||
See a [usage example](/docs/integrations/tools/you).
|
||||
|
||||
```python
|
||||
from langchain_community.tools.you import YouSearchTool
|
||||
```
|
||||
@@ -1,403 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Neo4j\n",
|
||||
"\n",
|
||||
">[Neo4j](https://neo4j.com/docs/) is a graph database that stores nodes and relationships, that also supports native vector search.\n",
|
||||
"\n",
|
||||
"In the notebook, we'll demo the `SelfQueryRetriever` wrapped around a `Neo4j` vector store. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Creating a Neo4j vector store\n",
|
||||
"First we'll want to create a Neo4j vector store and seed it with some data. We've created a small demo set of documents that contain summaries of movies."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We want to use `OpenAIEmbeddings` so we have to get the OpenAI API Key."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: neo4j in /Users/moyi/git/langchain/env/lib/python3.11/site-packages (5.24.0)\n",
|
||||
"Requirement already satisfied: pytz in /Users/moyi/git/langchain/env/lib/python3.11/site-packages (from neo4j) (2024.1)\n",
|
||||
"Note: you may need to restart the kernel to use updated packages.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%pip install --upgrade neo4j"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"OpenAI API Key: ········\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Neo4j URL: ········\n",
|
||||
"Neo4j User Name: ········\n",
|
||||
"Neo4j Password: ········\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# To run this notebook, you can set up a free neo4j account on neo4j.com and input the following information.\n",
|
||||
"# (If you are having trouble connecting to the database, try using neo4j+ssc: instead of neo4j+s)\n",
|
||||
"\n",
|
||||
"os.environ[\"NEO4J_URI\"] = getpass.getpass(\"Neo4j URL:\")\n",
|
||||
"os.environ[\"NEO4J_USERNAME\"] = getpass.getpass(\"Neo4j User Name:\")\n",
|
||||
"os.environ[\"NEO4J_PASSWORD\"] = getpass.getpass(\"Neo4j Password:\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.vectorstores import Neo4jVector\n",
|
||||
"from langchain_core.documents import Document\n",
|
||||
"from langchain_openai import OpenAIEmbeddings\n",
|
||||
"\n",
|
||||
"embeddings = OpenAIEmbeddings()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: {severity: WARNING} {code: Neo.ClientNotification.Statement.FeatureDeprecationWarning} {category: DEPRECATION} {title: This feature is deprecated and will be removed in future versions.} {description: CALL subquery without a variable scope clause is now deprecated. Use CALL (row) { ... }} {position: line: 1, column: 21, offset: 20} for query: \"UNWIND $data AS row CALL { WITH row MERGE (c:`Chunk` {id: row.id}) WITH c, row CALL db.create.setNodeVectorProperty(c, 'embedding', row.embedding) SET c.`text` = row.text SET c += row.metadata } IN TRANSACTIONS OF 1000 ROWS \"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"docs = [\n",
|
||||
" Document(\n",
|
||||
" page_content=\"A bunch of scientists bring back dinosaurs and mayhem breaks loose\",\n",
|
||||
" metadata={\"year\": 1993, \"rating\": 7.7, \"genre\": \"science fiction\"},\n",
|
||||
" ),\n",
|
||||
" Document(\n",
|
||||
" page_content=\"Leo DiCaprio gets lost in a dream within a dream within a dream within a ...\",\n",
|
||||
" metadata={\"year\": 2010, \"director\": \"Christopher Nolan\", \"rating\": 8.2},\n",
|
||||
" ),\n",
|
||||
" Document(\n",
|
||||
" page_content=\"A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea\",\n",
|
||||
" metadata={\"year\": 2006, \"director\": \"Satoshi Kon\", \"rating\": 8.6},\n",
|
||||
" ),\n",
|
||||
" Document(\n",
|
||||
" page_content=\"A bunch of normal-sized women are supremely wholesome and some men pine after them\",\n",
|
||||
" metadata={\"year\": 2019, \"director\": \"Greta Gerwig\", \"rating\": 8.3},\n",
|
||||
" ),\n",
|
||||
" Document(\n",
|
||||
" page_content=\"Toys come alive and have a blast doing so\",\n",
|
||||
" metadata={\"year\": 1995, \"genre\": \"animated\"},\n",
|
||||
" ),\n",
|
||||
" Document(\n",
|
||||
" page_content=\"Three men walk into the Zone, three men walk out of the Zone\",\n",
|
||||
" metadata={\n",
|
||||
" \"year\": 1979,\n",
|
||||
" \"director\": \"Andrei Tarkovsky\",\n",
|
||||
" \"genre\": \"science fiction\",\n",
|
||||
" \"rating\": 9.9,\n",
|
||||
" },\n",
|
||||
" ),\n",
|
||||
"]\n",
|
||||
"vectorstore = Neo4jVector.from_documents(docs, embeddings)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Creating our self-querying retriever\n",
|
||||
"Now we can instantiate our retriever. To do this we'll need to provide some information upfront about the metadata fields that our documents support and a short description of the document contents."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain.chains.query_constructor.base import AttributeInfo\n",
|
||||
"from langchain.retrievers.self_query.base import SelfQueryRetriever\n",
|
||||
"from langchain_openai import OpenAI\n",
|
||||
"\n",
|
||||
"metadata_field_info = [\n",
|
||||
" AttributeInfo(\n",
|
||||
" name=\"genre\",\n",
|
||||
" description=\"The genre of the movie\",\n",
|
||||
" type=\"string or list[string]\",\n",
|
||||
" ),\n",
|
||||
" AttributeInfo(\n",
|
||||
" name=\"year\",\n",
|
||||
" description=\"The year the movie was released\",\n",
|
||||
" type=\"integer\",\n",
|
||||
" ),\n",
|
||||
" AttributeInfo(\n",
|
||||
" name=\"director\",\n",
|
||||
" description=\"The name of the movie director\",\n",
|
||||
" type=\"string\",\n",
|
||||
" ),\n",
|
||||
" AttributeInfo(\n",
|
||||
" name=\"rating\", description=\"A 1-10 rating for the movie\", type=\"float\"\n",
|
||||
" ),\n",
|
||||
"]\n",
|
||||
"document_content_description = \"Brief summary of a movie\"\n",
|
||||
"llm = OpenAI(temperature=0)\n",
|
||||
"retriever = SelfQueryRetriever.from_llm(\n",
|
||||
" llm, vectorstore, document_content_description, metadata_field_info, verbose=True\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Testing it out\n",
|
||||
"And now we can try actually using our retriever!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[Document(metadata={'genre': 'science fiction', 'year': 1993, 'rating': 7.7}, page_content='A bunch of scientists bring back dinosaurs and mayhem breaks loose'),\n",
|
||||
" Document(metadata={'genre': 'animated', 'year': 1995}, page_content='Toys come alive and have a blast doing so'),\n",
|
||||
" Document(metadata={'genre': 'science fiction', 'year': 1979, 'rating': 9.9, 'director': 'Andrei Tarkovsky'}, page_content='Three men walk into the Zone, three men walk out of the Zone'),\n",
|
||||
" Document(metadata={'year': 2006, 'rating': 8.6, 'director': 'Satoshi Kon'}, page_content='A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This example only specifies a relevant query\n",
|
||||
"retriever.invoke(\"What are some movies about dinosaurs\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[Document(metadata={'genre': 'science fiction', 'year': 1979, 'rating': 9.9, 'director': 'Andrei Tarkovsky'}, page_content='Three men walk into the Zone, three men walk out of the Zone'),\n",
|
||||
" Document(metadata={'year': 2006, 'rating': 8.6, 'director': 'Satoshi Kon'}, page_content='A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This example only specifies a filter\n",
|
||||
"retriever.invoke(\"I want to watch a movie rated higher than 8.5\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[Document(metadata={'year': 2019, 'rating': 8.3, 'director': 'Greta Gerwig'}, page_content='A bunch of normal-sized women are supremely wholesome and some men pine after them')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This example specifies a query and a filter\n",
|
||||
"retriever.invoke(\"Has Greta Gerwig directed any movies about women\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[Document(metadata={'year': 2006, 'rating': 8.6, 'director': 'Satoshi Kon'}, page_content='A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea'),\n",
|
||||
" Document(metadata={'genre': 'science fiction', 'year': 1979, 'rating': 9.9, 'director': 'Andrei Tarkovsky'}, page_content='Three men walk into the Zone, three men walk out of the Zone')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This example specifies a composite filter\n",
|
||||
"retriever.invoke(\"What's a highly rated (above 8.5) science fiction film?\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[Document(metadata={'genre': 'animated', 'year': 1995}, page_content='Toys come alive and have a blast doing so')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This example specifies a query and composite filter\n",
|
||||
"retriever.invoke(\n",
|
||||
" \"What's a movie after 1990 but before 2005 that's all about toys, and preferably is animated\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Filter k\n",
|
||||
"\n",
|
||||
"We can also use the self query retriever to specify `k`: the number of documents to fetch.\n",
|
||||
"\n",
|
||||
"We can do this by passing `enable_limit=True` to the constructor."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"retriever = SelfQueryRetriever.from_llm(\n",
|
||||
" llm,\n",
|
||||
" vectorstore,\n",
|
||||
" document_content_description,\n",
|
||||
" metadata_field_info,\n",
|
||||
" enable_limit=True,\n",
|
||||
" verbose=True,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[Document(metadata={'genre': 'science fiction', 'year': 1993, 'rating': 7.7}, page_content='A bunch of scientists bring back dinosaurs and mayhem breaks loose'),\n",
|
||||
" Document(metadata={'genre': 'animated', 'year': 1995}, page_content='Toys come alive and have a blast doing so')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This example only specifies a relevant query\n",
|
||||
"retriever.invoke(\"what are two movies about dinosaurs\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
"source": [
|
||||
"# BGE on Hugging Face\n",
|
||||
"\n",
|
||||
">[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en-v1.5) are one of [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).\n",
|
||||
">[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en) are [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).\n",
|
||||
">BGE model is created by the [Beijing Academy of Artificial Intelligence (BAAI)](https://en.wikipedia.org/wiki/Beijing_Academy_of_Artificial_Intelligence). `BAAI` is a private non-profit organization engaged in AI research and development.\n",
|
||||
"\n",
|
||||
"This notebook shows how to use `BGE Embeddings` through `Hugging Face`"
|
||||
|
||||
@@ -1,307 +1,89 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "afaf8039",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"sidebar_label: Google Vertex AI \n",
|
||||
"keywords: [Vertex AI, vertexai , Google Cloud, embeddings]\n",
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9a3d6f34",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Google Vertex AI Embeddings \n",
|
||||
"# Google Vertex AI PaLM \n",
|
||||
"\n",
|
||||
"This will help you get started with Google Vertex AI Embeddings models using LangChain. For detailed documentation on `Google Vertex AI Embeddings` features and configuration options, please refer to the [API reference](https://python.langchain.com/v0.2/api_reference/google_vertexai/embeddings/langchain_google_vertexai.embeddings.VertexAIEmbeddings.html).\n",
|
||||
">[Vertex AI PaLM API](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview) is a service on Google Cloud exposing the embedding models. \n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"### Integration details\n",
|
||||
"Note: This integration is separate from the Google PaLM integration.\n",
|
||||
"\n",
|
||||
"| Provider | Package |\n",
|
||||
"|:--------:|:-------:|\n",
|
||||
"| [Google](https://python.langchain.com/v0.2/docs/integrations/platforms/google/) | [langchain-google-vertexai](https://python.langchain.com/v0.2/api_reference/google_vertexai/embeddings/langchain_google_vertexai.embeddings.VertexAIEmbeddings.html) |\n",
|
||||
"By default, Google Cloud [does not use](https://cloud.google.com/vertex-ai/docs/generative-ai/data-governance#foundation_model_development) Customer Data to train its foundation models as part of Google Cloud`s AI/ML Privacy Commitment. More details about how Google processes data can also be found in [Google's Customer Data Processing Addendum (CDPA)](https://cloud.google.com/terms/data-processing-addendum).\n",
|
||||
"\n",
|
||||
"## Setup\n",
|
||||
"To use Vertex AI PaLM you must have the `langchain-google-vertexai` Python package installed and either:\n",
|
||||
"- Have credentials configured for your environment (gcloud, workload identity, etc...)\n",
|
||||
"- Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable\n",
|
||||
"\n",
|
||||
"To access Google Vertex AI Embeddings models you'll need to \n",
|
||||
"- Create a Google Cloud account \n",
|
||||
"- Install the `langchain-google-vertexai` integration package.\n",
|
||||
"This codebase uses the `google.auth` library which first looks for the application credentials variable mentioned above, and then looks for system-level auth.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Credentials\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Head to [Google Cloud](https://cloud.google.com/free/) to sign up to create an account. Once you've done this set the GOOGLE_APPLICATION_CREDENTIALS environment variable:\n",
|
||||
"\n",
|
||||
"For more information, see:\n",
|
||||
"\n",
|
||||
"https://cloud.google.com/docs/authentication/application-default-credentials#GAC\n",
|
||||
"https://googleapis.dev/python/google-auth/latest/reference/google.auth.html#module-google.auth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "caaba519-3476-423b-a5e4-d99a10929506",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**OPTIONAL : Authenticate your notebook environment (Colab only)**\n",
|
||||
"\n",
|
||||
"If you're running this notebook on Google Colab, run the cell below to authenticate your environment."
|
||||
"For more information, see: \n",
|
||||
"- https://cloud.google.com/docs/authentication/application-default-credentials#GAC\n",
|
||||
"- https://googleapis.dev/python/google-auth/latest/reference/google.auth.html#module-google.auth\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b0770000-3667-439b-8c46-acc5af7c8e40",
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"if \"google.colab\" in sys.modules:\n",
|
||||
" from google.colab import auth\n",
|
||||
"\n",
|
||||
" auth.authenticate_user()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9fbd4a33-2480-4ad1-8d56-aec730b3662b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Set Google Cloud project information and initialize Vertex AI SDK**\n",
|
||||
"\n",
|
||||
"To get started using Vertex AI, you must have an existing Google Cloud project and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
|
||||
"\n",
|
||||
"Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)."
|
||||
"%pip install --upgrade --quiet langchain langchain-google-vertexai"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "36521c2a",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
|
||||
"LOCATION = \"us-central1\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"import vertexai\n",
|
||||
"\n",
|
||||
"vertexai.init(project=PROJECT_ID, location=LOCATION)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c84fb993",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you want to get automated tracing of your model calls you can also set your [LangSmith](https://docs.smith.langchain.com/) API key by uncommenting below:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "39a4953b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
|
||||
"# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"Enter your LangSmith API key: \")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d9664366",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Installation\n",
|
||||
"\n",
|
||||
"The LangChain Google Vertex AI Embeddings integration lives in the `langchain-google-vertexai` package:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "64853226",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -qU langchain-google-vertexai"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "45dd1724",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Instantiation\n",
|
||||
"\n",
|
||||
"Now we can instantiate our model object and generate embeddings:\n",
|
||||
">Check the list of [Supported Models](https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings#supported-models)"
|
||||
"from langchain_google_vertexai import VertexAIEmbeddings"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "9ea7a09b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_google_vertexai import VertexAIEmbeddings\n",
|
||||
"\n",
|
||||
"# Initialize the a specific Embeddings Model version\n",
|
||||
"embeddings = VertexAIEmbeddings(model_name=\"text-embedding-004\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "77d271b6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Indexing and Retrieval\n",
|
||||
"\n",
|
||||
"Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials under the [working with external knowledge tutorials](/docs/tutorials/#working-with-external-knowledge).\n",
|
||||
"\n",
|
||||
"Below, see how to index and retrieve data using the `embeddings` object we initialized above. In this example, we will index and retrieve a sample document in the `InMemoryVectorStore`."
|
||||
"embeddings = VertexAIEmbeddings()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "d817716b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'LangChain is the framework for building context-aware reasoning applications'"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create a vector store with a sample text\n",
|
||||
"from langchain_core.vectorstores import InMemoryVectorStore\n",
|
||||
"\n",
|
||||
"text = \"LangChain is the framework for building context-aware reasoning applications\"\n",
|
||||
"\n",
|
||||
"vectorstore = InMemoryVectorStore.from_texts(\n",
|
||||
" [text],\n",
|
||||
" embedding=embeddings,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Use the vectorstore as a retriever\n",
|
||||
"retriever = vectorstore.as_retriever()\n",
|
||||
"\n",
|
||||
"# Retrieve the most similar text\n",
|
||||
"retrieved_documents = retriever.invoke(\"What is LangChain?\")\n",
|
||||
"\n",
|
||||
"# show the retrieved document's content\n",
|
||||
"retrieved_documents[0].page_content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e02b9855",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Direct Usage\n",
|
||||
"\n",
|
||||
"Under the hood, the vectorstore and retriever implementations are calling `embeddings.embed_documents(...)` and `embeddings.embed_query(...)` to create embeddings for the text(s) used in `from_texts` and retrieval `invoke` operations, respectively.\n",
|
||||
"\n",
|
||||
"You can directly call these methods to get embeddings for your own use cases.\n",
|
||||
"\n",
|
||||
"### Embed single texts\n",
|
||||
"\n",
|
||||
"You can embed single texts or documents with `embed_query`:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "0d2befcd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[-0.02831101417541504, 0.022063178941607475, -0.07454229146242142, 0.006448323838412762, 0.001955120\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"single_vector = embeddings.embed_query(text)\n",
|
||||
"print(str(single_vector)[:100]) # Show the first 100 characters of the vector"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1b5a7d03",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Embed multiple texts\n",
|
||||
"\n",
|
||||
"You can embed multiple texts with `embed_documents`:"
|
||||
"text = \"This is a test document.\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "2f4d6e97",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[-0.01092718355357647, 0.01213780976831913, -0.05650627985596657, 0.006737854331731796, 0.0085973171\n",
|
||||
"[0.010135706514120102, 0.01234869472682476, -0.07284046709537506, 0.00027134662377648056, 0.01546290\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"text2 = (\n",
|
||||
" \"LangGraph is a library for building stateful, multi-actor applications with LLMs\"\n",
|
||||
")\n",
|
||||
"two_vectors = embeddings.embed_documents([text, text2])\n",
|
||||
"for vector in two_vectors:\n",
|
||||
" print(str(vector)[:100]) # Show the first 100 characters of the vector"
|
||||
"query_result = embeddings.embed_query(text)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "98785c12",
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"## API Reference\n",
|
||||
"\n",
|
||||
"For detailed documentation on `Google Vertex AI Embeddings\n",
|
||||
"` features and configuration options, please refer to the [API reference](https://python.langchain.com/v0.2/api_reference/google_vertexai/embeddings/langchain_google_vertexai.embeddings.VertexAIEmbeddings.html).\n"
|
||||
"doc_result = embeddings.embed_documents([text])"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"environment": {
|
||||
"kernel": "python310",
|
||||
"name": "tf2-gpu.2-6.m104",
|
||||
"type": "gcloud",
|
||||
"uri": "gcr.io/deeplearning-platform-release/tf2-gpu.2-6:m104"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -315,9 +97,14 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.6"
|
||||
"version": "3.10.12"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "cc99336516f23363341912c6723b01ace86f02e26b4290be1efc0677e2e2ec24"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\")"
|
||||
"embeddings = HuggingFaceEmbeddings()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
"## Install Prerequisites\n",
|
||||
"To benefit from IPEX-LLM on Intel GPUs, there are several prerequisite steps for tools installation and environment preparation.\n",
|
||||
"\n",
|
||||
"If you are a Windows user, visit the [Install IPEX-LLM on Windows with Intel GPU Guide](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md), and follow [Install Prerequisites](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md#install-prerequisites) to update GPU driver (optional) and install Conda.\n",
|
||||
"If you are a Windows user, visit the [Install IPEX-LLM on Windows with Intel GPU Guide](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_windows_gpu.html), and follow [Install Prerequisites](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_windows_gpu.html#install-prerequisites) to update GPU driver (optional) and install Conda.\n",
|
||||
"\n",
|
||||
"If you are a Linux user, visit the [Install IPEX-LLM on Linux with Intel GPU](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md), and follow [**Install Prerequisites**](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md#install-prerequisites) to install GPU driver, Intel® oneAPI Base Toolkit 2024.0, and Conda.\n",
|
||||
"If you are a Linux user, visit the [Install IPEX-LLM on Linux with Intel GPU](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_linux_gpu.html), and follow [**Install Prerequisites**](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_linux_gpu.html#install-prerequisites) to install GPU driver, Intel® oneAPI Base Toolkit 2024.0, and Conda.\n",
|
||||
"\n",
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
@@ -105,7 +105,7 @@
|
||||
">\n",
|
||||
"> For the first time that each model runs on Intel iGPU/Intel Arc A300-Series or Pro A60, it may take several minutes to compile.\n",
|
||||
">\n",
|
||||
"> For other GPU type, please refer to [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration) for Windows users, and [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration-1) for Linux users.\n",
|
||||
"> For other GPU type, please refer to [here](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Overview/install_gpu.html#runtime-configuration) for Windows users, and [here](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Overview/install_gpu.html#id5) for Linux users.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Basic Usage\n",
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
"# Google Cloud Text-to-Speech\n",
|
||||
"\n",
|
||||
">[Google Cloud Text-to-Speech](https://cloud.google.com/text-to-speech) enables developers to synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants. It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks to deliver the highest fidelity possible.\n",
|
||||
">\n",
|
||||
">It supports multiple languages, including English, German, Polish, Spanish, Italian, French, Portuguese, and Hindi.\n",
|
||||
"\n",
|
||||
"This notebook shows how to interact with the `Google Cloud Text-to-Speech API` to achieve speech synthesis capabilities."
|
||||
]
|
||||
@@ -24,38 +22,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "0a309c0e-5310-4eaa-8af9-bcbc252e45da",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install --upgrade langchain-google-community[texttospeech]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5b86ad38-ac8a-4f0a-a492-01a6e3090c8c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Instantiation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "e2efded2-894b-4683-89ed-2a6948913fa9",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-09-01T17:47:31.565221Z",
|
||||
"iopub.status.busy": "2024-09-01T17:47:31.564804Z",
|
||||
"iopub.status.idle": "2024-09-01T17:47:31.570600Z",
|
||||
"shell.execute_reply": "2024-09-01T17:47:31.569764Z",
|
||||
"shell.execute_reply.started": "2024-09-01T17:47:31.565188Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_google_community import TextToSpeechTool"
|
||||
"%pip install --upgrade --quiet google-cloud-text-to-speech langchain-community"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -63,34 +35,18 @@
|
||||
"id": "434b2454-2bff-484d-822c-4026a9dc1383",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Deprecated GoogleCloudTextToSpeechTool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "2f57a647-9214-4562-a8cf-f263a15d1f40",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-09-01T17:51:28.763915Z",
|
||||
"iopub.status.busy": "2024-09-01T17:51:28.763664Z",
|
||||
"iopub.status.idle": "2024-09-01T17:51:28.779073Z",
|
||||
"shell.execute_reply": "2024-09-01T17:51:28.778477Z",
|
||||
"shell.execute_reply.started": "2024-09-01T17:51:28.763897Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools import GoogleCloudTextToSpeechTool"
|
||||
"## Usage"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a2647bc5-e494-41f9-9f53-4a278ea30cc1",
|
||||
"id": "2f57a647-9214-4562-a8cf-f263a15d1f40",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools import GoogleCloudTextToSpeechTool\n",
|
||||
"\n",
|
||||
"text_to_speak = \"Hello world!\"\n",
|
||||
"\n",
|
||||
"tts = GoogleCloudTextToSpeechTool()\n",
|
||||
|
||||
@@ -1,284 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "10238e62-3465-4973-9279-606cbb7ccf16",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"sidebar_label: Jina Search\n",
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a6f91f20",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Jina Search\n",
|
||||
"\n",
|
||||
"This notebook provides a quick overview for getting started with Jina [tool](/docs/integrations/tools/). For detailed documentation of all Jina features and configurations head to the [API reference](https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.jina_search.tool.JinaSearch.html).\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"### Integration details\n",
|
||||
"\n",
|
||||
"| Class | Package | Serializable | JS support | Package latest |\n",
|
||||
"| :--- | :--- | :---: | :---: | :---: |\n",
|
||||
"| [JinaSearch](https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.jina_search.tool.JinaSearch.html) | [langchain-community](https://python.langchain.com/v0.2/api_reference/community/) | ❌ | ❌ |  |\n",
|
||||
"\n",
|
||||
"### Tool features\n",
|
||||
"| [Returns artifact](/docs/how_to/tool_artifacts/) | Native async | Return data | Pricing |\n",
|
||||
"| :---: | :---: | :---: | :---: |\n",
|
||||
"| ❌ | ❌ | URL, Snippet, Title, Page Content | 1M response tokens free | \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
"The integration lives in the `langchain-community` package and was added in version `0.2.16`:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f85b4089",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --quiet -U \"langchain-community>=0.2.16\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b15e9266",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Credentials"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "e0b178a2-8816-40ca-b57c-ccdd86dde9c9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bc5ab717-fd27-4c59-b912-bdd099541478",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/) for best-in-class observability:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "a6c2f136-6367-4f1f-825d-ae741e1bf281",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
|
||||
"# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1c97218f-f366-479d-8bf7-fe9f2f6df73f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Instantiation\n",
|
||||
"\n",
|
||||
"- TODO: Fill in instantiation params\n",
|
||||
"\n",
|
||||
"Here we show how to instantiate an instance of the Jina tool, with "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "8b3ddfe9-ca79-494c-a7ab-1f56d9407a64",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools import JinaSearch\n",
|
||||
"\n",
|
||||
"tool = JinaSearch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "74147a1a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Invocation\n",
|
||||
"\n",
|
||||
"### [Invoke directly with args](/docs/concepts/#invoke-with-just-the-arguments)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "65310a8b-eb0c-4d9e-a618-4f4abe2414fc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[{\"title\": \"LangGraph\", \"link\": \"https://www.langchain.com/langgraph\", \"snippet\": \"<strong>LangGraph</strong> helps teams of all sizes, across all industries, from ambitious startups to established enterprises. \\u201cLangChain is streets ahead with what they've put forward with <strong>LangGraph</strong>.\", \"content\": \"\\n\\nControllable cognitive architecture for any task\\n------------------------------------------------\\n\\nLangGraph's flexible API supports diverse control flows \\u2013 single agent, multi-agent, hierarchical, sequential \\u2013 and robustly handles realistic, complex scenarios.\\n\\nEnsure reliability with easy-to-add moderation and quality loops that prevent agents from veering off course.\\n\\n[See the docs](https://langchain-ai.github.io/langgraph/)\\n\\nDesigned for human-agent collaboration\\n--------------------------------------\\n\\nWith built-in stat\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(tool.invoke({\"query\": \"what is langgraph\"})[:1000])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d6e73897",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### [Invoke with ToolCall](/docs/concepts/#invoke-with-toolcall)\n",
|
||||
"\n",
|
||||
"We can also invoke the tool with a model-generated ToolCall, in which case a ToolMessage will be returned:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "f90e33a7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[{\"title\": \"LangGraph Tutorial: What Is LangGraph and How to Use It?\", \"link\": \"https://www.datacamp.com/tutorial/langgraph-tutorial\", \"snippet\": \"<strong>LangGraph</strong> <strong>is</strong> a library within the LangChain ecosystem that provides a framework for defining, coordinating, and executing multiple LLM agents (or chains) in a structured and efficient manner.\", \"content\": \"Imagine you're building a complex, multi-agent large language model (LLM) application. It's exciting, but it comes with challenges: managing the state of various agents, coordinating their interactions, and handling errors effectively. This is where LangGraph can help.\\n\\nLangGraph is a library within the LangChain ecosystem designed to tackle these challenges head-on. LangGraph provides a framework for defining, coordinating, and executing multiple LLM agents (or chains) in a structured manner.\\n\\nIt simplifies the development process by enabling the creation of cyclical graphs, which are essential for de\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This is usually generated by a model, but we'll create a tool call directly for demo purposes.\n",
|
||||
"model_generated_tool_call = {\n",
|
||||
" \"args\": {\"query\": \"what is langgraph\"},\n",
|
||||
" \"id\": \"1\",\n",
|
||||
" \"name\": tool.name,\n",
|
||||
" \"type\": \"tool_call\",\n",
|
||||
"}\n",
|
||||
"tool_msg = tool.invoke(model_generated_tool_call)\n",
|
||||
"print(tool_msg.content[:1000])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "659f9fbd-6fcf-445f-aa8c-72d8e60154bd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Chaining\n",
|
||||
"\n",
|
||||
"We can use our tool in a chain by first binding it to a [tool-calling model](/docs/how_to/tool_calling/) and then calling it:\n",
|
||||
"\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
"\n",
|
||||
"<ChatModelTabs customVarName=\"llm\" />\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "af3123ad-7a02-40e5-b58e-7d56e23e5830",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# | output: false\n",
|
||||
"# | echo: false\n",
|
||||
"\n",
|
||||
"# !pip install -qU langchain langchain-openai\n",
|
||||
"from langchain.chat_models import init_chat_model\n",
|
||||
"\n",
|
||||
"llm = init_chat_model(model=\"gpt-4o\", model_provider=\"openai\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "fdbf35b5-3aaf-4947-9ec6-48c21533fb95",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content=\"LangGraph is a library designed for building stateful, multi-actor applications with language models (LLMs). It is particularly useful for creating agent and multi-agent workflows. Compared to other LLM frameworks, LangGraph offers unique benefits such as cycles, controllability, and persistence. Here are some key points:\\n\\n1. **Stateful and Multi-Actor Applications**: LangGraph allows for the definition of flows involving cycles, essential for most agentic architectures. This is a significant differentiation from Directed Acyclic Graph (DAG)-based solutions.\\n\\n2. **Controllability**: The framework offers fine-grained control over both the flow and state of applications, which is crucial for creating reliable agents.\\n\\n3. **Persistence**: Built-in persistence is available, enabling advanced features like human-in-the-loop workflows and memory.\\n\\n4. **Human-in-the-Loop**: LangGraph supports interrupting graph execution for human approval or editing of the agent's next planned action.\\n\\n5. **Streaming Support**: The library can stream outputs as they are produced by each node, including token streaming.\\n\\n6. **Integration with LangChain**: While it integrates seamlessly with LangChain and LangSmith, LangGraph can also be used independently.\\n\\n7. **Inspiration and Interface**: LangGraph is inspired by systems like Pregel and Apache Beam, with its public interface drawing inspiration from NetworkX.\\n\\nLangGraph is designed to handle more complex agent applications that require cycles and state management, making it an ideal choice for developers seeking to build sophisticated LLM-driven applications. For more detailed information, you can visit their [official documentation](https://langchain-ai.github.io/langgraph/).\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 338, 'prompt_tokens': 14774, 'total_tokens': 15112}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_157b3831f5', 'finish_reason': 'stop', 'logprobs': None}, id='run-420d16ed-535c-41c6-8814-2186b42be0f8-0', usage_metadata={'input_tokens': 14774, 'output_tokens': 338, 'total_tokens': 15112})"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.runnables import RunnableConfig, chain\n",
|
||||
"\n",
|
||||
"prompt = ChatPromptTemplate(\n",
|
||||
" [\n",
|
||||
" (\"system\", \"You are a helpful assistant.\"),\n",
|
||||
" (\"human\", \"{user_input}\"),\n",
|
||||
" (\"placeholder\", \"{messages}\"),\n",
|
||||
" ]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"llm_with_tools = llm.bind_tools([tool])\n",
|
||||
"llm_chain = prompt | llm_with_tools\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@chain\n",
|
||||
"def tool_chain(user_input: str, config: RunnableConfig):\n",
|
||||
" input_ = {\"user_input\": user_input}\n",
|
||||
" ai_msg = llm_chain.invoke(input_, config=config)\n",
|
||||
" tool_msgs = tool.batch(ai_msg.tool_calls, config=config)\n",
|
||||
" return llm_chain.invoke({**input_, \"messages\": [ai_msg, *tool_msgs]}, config=config)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"tool_chain.invoke(\"what's langgraph\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4ac8146c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## API reference\n",
|
||||
"\n",
|
||||
"For detailed documentation of all Jina features and configurations head to the API reference: https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.jina_search.tool.JinaSearch.html"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "poetry-venv-311",
|
||||
"language": "python",
|
||||
"name": "poetry-venv-311"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -57,8 +57,7 @@
|
||||
"from langchain_community.vectorstores import Annoy\n",
|
||||
"from langchain_huggingface import HuggingFaceEmbeddings\n",
|
||||
"\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings_func = HuggingFaceEmbeddings(model_name=model_name)"
|
||||
"embeddings_func = HuggingFaceEmbeddings()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
"source": [
|
||||
"# Faiss\n",
|
||||
"\n",
|
||||
">[Facebook AI Similarity Search (FAISS)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also includes supporting code for evaluation and parameter tuning.\n",
|
||||
">\n",
|
||||
">See [The FAISS Library](https://arxiv.org/pdf/2401.08281) paper.\n",
|
||||
">[Facebook AI Similarity Search (FAISS)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning.\n",
|
||||
"\n",
|
||||
"You can find the FAISS documentation at [this page](https://faiss.ai/).\n",
|
||||
"\n",
|
||||
@@ -530,7 +528,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
"source": [
|
||||
"# Faiss (Async)\n",
|
||||
"\n",
|
||||
">[Facebook AI Similarity Search (Faiss)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also includes supporting code for evaluation and parameter tuning.\n",
|
||||
">\n",
|
||||
">See [The FAISS Library](https://arxiv.org/pdf/2401.08281) paper.\n",
|
||||
">[Facebook AI Similarity Search (Faiss)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning.\n",
|
||||
"\n",
|
||||
"[Faiss documentation](https://faiss.ai/).\n",
|
||||
"\n",
|
||||
|
||||
@@ -325,13 +325,7 @@
|
||||
"id": "20cf6074081b"
|
||||
},
|
||||
"source": [
|
||||
"### Searching Documents with Metadata Filters\n",
|
||||
"The vectorstore supports two methods for applying filters to metadata fields when performing document searches:\n",
|
||||
"\n",
|
||||
"- Dictionary-based Filters\n",
|
||||
" - You can pass a dictionary (dict) where the keys represent metadata fields and the values specify the filter condition. This method applies an equality filter between the key and the corresponding value. When multiple key-value pairs are provided, they are combined using a logical AND operation.\n",
|
||||
"- SQL-based Filters\n",
|
||||
" - Alternatively, you can provide a string representing an SQL WHERE clause to define more complex filtering conditions. This allows for greater flexibility, supporting SQL expressions such as comparison operators and logical operators."
|
||||
"### Search for documents with metadata filter"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -342,24 +336,11 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Dictionary-based Filters\n",
|
||||
"# This should only return \"Banana\" document.\n",
|
||||
"docs = store.similarity_search_by_vector(query_vector, filter={\"len\": 6})\n",
|
||||
"print(docs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# SQL-based Filters\n",
|
||||
"# This should return \"Banana\", \"Apples and oranges\" and \"Cars and airplanes\" documents.\n",
|
||||
"docs = store.similarity_search_by_vector(query_vector, filter={\"len = 6 AND len > 17\"})\n",
|
||||
"print(docs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
@@ -61,8 +61,7 @@
|
||||
"docs = text_splitter.split_documents(documents)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"\n",
|
||||
"db = ScaNN.from_documents(docs, embeddings)\n",
|
||||
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
|
||||
|
||||
@@ -45,8 +45,7 @@
|
||||
"source": [
|
||||
"from langchain_huggingface import HuggingFaceEmbeddings\n",
|
||||
"\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)"
|
||||
"embeddings = HuggingFaceEmbeddings()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -92,8 +92,7 @@
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"docs = text_splitter.split_documents(documents)\n",
|
||||
"\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)"
|
||||
"embeddings = HuggingFaceEmbeddings()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -51,8 +51,7 @@
|
||||
"raw_documents = TextLoader(\"../../how_to/state_of_the_union.txt\").load()\n",
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"documents = text_splitter.split_documents(raw_documents)\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"db = TileDB.from_documents(\n",
|
||||
" documents, embeddings, index_uri=\"/tmp/tiledb_index\", index_type=\"FLAT\"\n",
|
||||
")"
|
||||
|
||||
@@ -50,8 +50,7 @@
|
||||
"raw_documents = TextLoader(\"state_of_the_union.txt\").load()\n",
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"documents = text_splitter.split_documents(raw_documents)\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"db = Vald.from_documents(documents, embeddings, host=\"localhost\", port=8080)"
|
||||
]
|
||||
},
|
||||
@@ -198,8 +197,7 @@
|
||||
"raw_documents = TextLoader(\"state_of_the_union.txt\").load()\n",
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"documents = text_splitter.split_documents(raw_documents)\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"\n",
|
||||
"db = Vald.from_documents(\n",
|
||||
" documents,\n",
|
||||
|
||||
@@ -200,8 +200,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"# create the open-source embedding function\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embedding = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"embedding = HuggingFaceEmbeddings()\n",
|
||||
"print(\n",
|
||||
" f\"# Embedding Dimensions: {len(embedding.embed_query('This is a test document.'))}\"\n",
|
||||
")"
|
||||
|
||||
@@ -55,7 +55,7 @@ These are the best ones to get started with:
|
||||
- [Build an Agent](/docs/tutorials/agents)
|
||||
- [Introduction to LangGraph](https://langchain-ai.github.io/langgraph/tutorials/introduction/)
|
||||
|
||||
Explore the full list of LangChain tutorials [here](/docs/tutorials), and check out other [LangGraph tutorials here](https://langchain-ai.github.io/langgraph/tutorials/). To learn more about LangGraph, check out our first LangChain Academy course, *Introduction to LangGraph*, available [here](https://academy.langchain.com/courses/intro-to-langgraph).
|
||||
Explore the full list of LangChain tutorials [here](/docs/tutorials), and check out other [LangGraph tutorials here](https://langchain-ai.github.io/langgraph/tutorials/).
|
||||
|
||||
|
||||
## [How-to guides](/docs/how_to)
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
"\n",
|
||||
"## Quickstart\n",
|
||||
"\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangeably - select the one you want to use below!\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangably - select the one you want to use below!\n",
|
||||
"\n",
|
||||
"```{=mdx}\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
@@ -254,7 +254,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install langchain_community"
|
||||
"# ! pip install langchain_community"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -952,7 +952,7 @@
|
||||
"source": [
|
||||
"## Streaming\n",
|
||||
"\n",
|
||||
"Now we've got a functioning chatbot. However, one *really* important UX consideration for chatbot applications is streaming. LLMs can sometimes take a while to respond, and so in order to improve the user experience one thing that most applications do is stream back each token as it is generated. This allows the user to see progress.\n",
|
||||
"Now we've got a function chatbot. However, one *really* important UX consideration for chatbot application is streaming. LLMs can sometimes take a while to respond, and so in order to improve the user experience one thing that most application do is stream back each token as it is generated. This allows the user to see progress.\n",
|
||||
"\n",
|
||||
"It's actually super easy to do this!\n",
|
||||
"\n",
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
"source": [
|
||||
"## Using Language Models\n",
|
||||
"\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangeably - select the one you want to use below!\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangably - select the one you want to use below!\n",
|
||||
"\n",
|
||||
"```{=mdx}\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
@@ -159,7 +159,9 @@
|
||||
"cell_type": "markdown",
|
||||
"id": "f83373db",
|
||||
"metadata": {},
|
||||
"source": "If we've enabled LangSmith, we can see that this run is logged to LangSmith, and can see the [LangSmith trace](https://smith.langchain.com/public/88baa0b2-7c1a-4d09-ba30-a47985dde2ea/r)"
|
||||
"source": [
|
||||
"If we've enable LangSmith, we can see that this run is logged to LangSmith, and can see the [LangSmith trace](https://smith.langchain.com/public/88baa0b2-7c1a-4d09-ba30-a47985dde2ea/r)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -477,6 +479,8 @@
|
||||
"\n",
|
||||
"```python\n",
|
||||
"#!/usr/bin/env python\n",
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"from fastapi import FastAPI\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.output_parsers import StrOutputParser\n",
|
||||
@@ -508,6 +512,7 @@
|
||||
")\n",
|
||||
"\n",
|
||||
"# 5. Adding chain route\n",
|
||||
"\n",
|
||||
"add_routes(\n",
|
||||
" app,\n",
|
||||
" chain,\n",
|
||||
|
||||
@@ -337,6 +337,8 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"from langchain_core.documents import Document\n",
|
||||
"from langchain_core.runnables import RunnableLambda\n",
|
||||
"\n",
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
"\n",
|
||||
"2. `Map-reduce`: Summarize each document on its own in a \"map\" step and then \"reduce\" the summaries into a final summary (see [here](https://python.langchain.com/v0.2/api_reference/langchain/chains/langchain.chains.combine_documents.map_reduce.MapReduceDocumentsChain.html) for more on the `MapReduceDocumentsChain`, which is used for this method).\n",
|
||||
"\n",
|
||||
"Note that map-reduce is especially effective when understanding of a sub-document does not rely on preceding context. For example, when summarizing a corpus of many, shorter documents. In other cases, such as summarizing a novel or body of text with an inherent sequence, [iterative refinement](/docs/how_to/summarize_refine) may be more effective."
|
||||
"Note that map-reduce is especially effective when understanding of a sub-document does not rely on preceeding context. For example, when summarizing a corpus of many, shorter documents. In other cases, such as summarizing a novel or body of text with an inherent sequence, [iterative refinement](/docs/how_to/summarize_refine) may be more effective."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -346,7 +346,7 @@
|
||||
"\n",
|
||||
"Note that the map step is typically parallelized over the input documents.\n",
|
||||
"\n",
|
||||
"[LangGraph](https://langchain-ai.github.io/langgraph/), built on top of `langchain-core`, supports [map-reduce](https://langchain-ai.github.io/langgraph/how-tos/map-reduce/) workflows and is well-suited to this problem:\n",
|
||||
"[LangGraph](https://langchain-ai.github.io/langgraph/), built on top of `langchain-core`, suports [map-reduce](https://langchain-ai.github.io/langgraph/how-tos/map-reduce/) workflows and is well-suited to this problem:\n",
|
||||
"\n",
|
||||
"- LangGraph allows for individual steps (such as successive summarizations) to be streamed, allowing for greater control of execution;\n",
|
||||
"- LangGraph's [checkpointing](https://langchain-ai.github.io/langgraph/how-tos/persistence/) supports error recovery, extending with human-in-the-loop workflows, and easier incorporation into conversational applications.\n",
|
||||
|
||||
@@ -125,11 +125,8 @@ const config = {
|
||||
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
|
||||
({
|
||||
announcementBar: {
|
||||
content:
|
||||
'Share your thoughts on AI agents. <a target="_blank" href="https://langchain.typeform.com/state-of-agents">Take the 3-min survey</a>.',
|
||||
content: 'LangChain 0.2 is out! Leave feedback on the v0.2 docs <a href="https://github.com/langchain-ai/langchain/discussions/21716">here</a>. You can view the v0.1 docs <a href="/v0.1/docs/get_started/introduction/">here</a>.',
|
||||
isCloseable: true,
|
||||
backgroundColor: "rgba(53, 151, 147, 0.1)",
|
||||
textColor: "rgb(53, 151, 147)",
|
||||
},
|
||||
docs: {
|
||||
sidebar: {
|
||||
|
||||
@@ -15,7 +15,6 @@ EXTERNAL_PACKAGES = {
|
||||
"astradb",
|
||||
"aws",
|
||||
"cohere",
|
||||
"databricks",
|
||||
"elasticsearch",
|
||||
"google-community",
|
||||
"google-genai",
|
||||
|
||||
@@ -62,11 +62,6 @@ SEARCH_TOOL_FEAT_TABLE = {
|
||||
"available_data": "Answer",
|
||||
"link": "/docs/integrations/tools/serpapi",
|
||||
},
|
||||
"Jina Search": {
|
||||
"pricing": "1M Response Tokens Free",
|
||||
"available_data": "URL, Snippet, Title, Page Content",
|
||||
"link": "/docs/integrations/tools/jina_search/",
|
||||
},
|
||||
}
|
||||
|
||||
CODE_INTERPRETER_TOOL_FEAT_TABLE = {
|
||||
|
||||
@@ -398,7 +398,6 @@ module.exports = {
|
||||
{ type: "doc", id: "contributing/documentation/style_guide", className: "hidden" },
|
||||
{ type: "doc", id: "contributing/documentation/setup", className: "hidden" },
|
||||
"contributing/testing",
|
||||
"contributing/review_process",
|
||||
"contributing/faq",
|
||||
],
|
||||
collapsible: false,
|
||||
|
||||
@@ -204,17 +204,6 @@ const FEATURE_TABLES = {
|
||||
"multimodal": false,
|
||||
"local": false,
|
||||
"apiLink": "https://python.langchain.com/v0.2/api_reference/upstage/chat_models/langchain_upstage.chat_models.ChatUpstage.html"
|
||||
},
|
||||
{
|
||||
"name": "ChatDatabricks",
|
||||
"package": "langchain-databricks",
|
||||
"link": "databricks",
|
||||
"structured_output": true,
|
||||
"tool_calling": true,
|
||||
"json_mode": false,
|
||||
"multimodal": false,
|
||||
"local": false,
|
||||
"apiLink": "https://python.langchain.com/v0.2/api_reference/upstage/chat_models/langchain_databricks.chat_models.ChatDatabricks.html"
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -358,12 +347,6 @@ const FEATURE_TABLES = {
|
||||
package: "langchain-nomic",
|
||||
apiLink: "https://python.langchain.com/v0.2/api_reference/nomic/embeddings/langchain_nomic.embeddings.NomicEmbeddings.html"
|
||||
},
|
||||
{
|
||||
name: "Databricks",
|
||||
link: "databricks",
|
||||
package: "langchain-databricks",
|
||||
apiLink: "https://python.langchain.com/v0.2/api_reference/nomic/embeddings/langchain_databricks.embeddings.DatabricksEmbeddings.html"
|
||||
},
|
||||
]
|
||||
},
|
||||
document_retrievers: {
|
||||
@@ -907,7 +890,7 @@ const FEATURE_TABLES = {
|
||||
{title: "Passes Standard Tests", formatter: (item) => item.passesStandardTests ? "✅" : "❌"},
|
||||
{title: "Multi Tenancy", formatter: (item) => item.multiTenancy ? "✅" : "❌"},
|
||||
{title: "IDs in add Documents", formatter: (item) => item.idsInAddDocuments ? "✅" : "❌"},
|
||||
// {title: "Local/Cloud", formatter: (item) => item.local ? "Local" : "Cloud"},
|
||||
{title: "Local/Cloud", formatter: (item) => item.local ? "Local" : "Cloud"},
|
||||
],
|
||||
items: [
|
||||
{
|
||||
@@ -962,26 +945,13 @@ const FEATURE_TABLES = {
|
||||
local: true,
|
||||
idsInAddDocuments: false,
|
||||
},
|
||||
{
|
||||
name: "DatabricksVectorSearch",
|
||||
link: "databricks_vector_search",
|
||||
deleteById: true,
|
||||
filtering: true,
|
||||
searchByVector: true,
|
||||
searchWithScore: true,
|
||||
async: true,
|
||||
passesStandardTests: false,
|
||||
multiTenancy: false,
|
||||
local: false,
|
||||
idsInAddDocuments: false,
|
||||
},
|
||||
{
|
||||
name: "ElasticsearchStore",
|
||||
link: "elasticsearch",
|
||||
deleteById: true,
|
||||
filtering: true,
|
||||
searchByVector: true,
|
||||
searchWithScore: true,
|
||||
searchWithScore: false,
|
||||
async: true,
|
||||
passesStandardTests: false,
|
||||
multiTenancy: false,
|
||||
@@ -1042,7 +1012,7 @@ const FEATURE_TABLES = {
|
||||
},
|
||||
{
|
||||
name: "PGVector",
|
||||
link: "pgvector",
|
||||
link: "pg_vector",
|
||||
deleteById: true,
|
||||
filtering: true,
|
||||
searchByVector: true,
|
||||
|
||||
BIN
docs/static/img/review_process_status.png
vendored
BIN
docs/static/img/review_process_status.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 161 KiB |
@@ -4,10 +4,6 @@
|
||||
"ignoreCommand": "bash ignore-step.sh",
|
||||
"trailingSlash": true,
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "/v0.2/docs/integrations(/?)",
|
||||
"destination": "/v0.2/docs/integrations/platforms/"
|
||||
},
|
||||
{
|
||||
"source": "/v0.1",
|
||||
"destination": "https://langchain-v01.vercel.app/v0.1"
|
||||
|
||||
@@ -12,9 +12,6 @@ integration_test integration_tests: TEST_FILE = tests/integration_tests/
|
||||
test tests:
|
||||
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)
|
||||
|
||||
test_watch:
|
||||
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)
|
||||
|
||||
# integration tests are run without the --disable-socket flag to allow network calls
|
||||
integration_test integration_tests:
|
||||
poetry run pytest $(TEST_FILE)
|
||||
|
||||
@@ -23,7 +23,6 @@ pytest = "^7.4.3"
|
||||
pytest-asyncio = "^0.23.2"
|
||||
pytest-socket = "^0.7.0"
|
||||
langchain-core = { path = "../../core", develop = true }
|
||||
pytest-watcher = "^0.3.4"
|
||||
|
||||
[tool.poetry.group.codespell]
|
||||
optional = true
|
||||
|
||||
@@ -91,7 +91,7 @@ def _is_assistants_builtin_tool(
|
||||
A boolean response of true or false indicating if the tool corresponds to
|
||||
OpenAI Assistants built-in.
|
||||
"""
|
||||
assistants_builtin_tools = ("code_interpreter", "retrieval", "file_search")
|
||||
assistants_builtin_tools = ("code_interpreter", "retrieval")
|
||||
return (
|
||||
isinstance(tool, dict)
|
||||
and ("type" in tool)
|
||||
|
||||
@@ -16,7 +16,6 @@ from langchain_core.messages import (
|
||||
ChatMessageChunk,
|
||||
HumanMessage,
|
||||
HumanMessageChunk,
|
||||
SystemMessage,
|
||||
)
|
||||
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
|
||||
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
|
||||
@@ -34,8 +33,6 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
message_dict: Dict[str, Any]
|
||||
if isinstance(message, ChatMessage):
|
||||
message_dict = {"Role": message.role, "Content": message.content}
|
||||
elif isinstance(message, SystemMessage):
|
||||
message_dict = {"Role": "system", "Content": message.content}
|
||||
elif isinstance(message, HumanMessage):
|
||||
message_dict = {"Role": "user", "Content": message.content}
|
||||
elif isinstance(message, AIMessage):
|
||||
@@ -48,9 +45,7 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
|
||||
def _convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage:
|
||||
role = _dict["Role"]
|
||||
if role == "system":
|
||||
return SystemMessage(content=_dict.get("Content", "") or "")
|
||||
elif role == "user":
|
||||
if role == "user":
|
||||
return HumanMessage(content=_dict["Content"])
|
||||
elif role == "assistant":
|
||||
return AIMessage(content=_dict.get("Content", "") or "")
|
||||
@@ -78,7 +73,6 @@ def _create_chat_result(response: Mapping[str, Any]) -> ChatResult:
|
||||
generations = []
|
||||
for choice in response["Choices"]:
|
||||
message = _convert_dict_to_message(choice["Message"])
|
||||
message.id = response.get("Id", "")
|
||||
generations.append(ChatGeneration(message=message))
|
||||
|
||||
token_usage = response["Usage"]
|
||||
@@ -121,7 +115,7 @@ class ChatHunyuan(BaseChatModel):
|
||||
model: str = "hunyuan-lite"
|
||||
"""What Model to use.
|
||||
Optional model:
|
||||
- hunyuan-lite
|
||||
- hunyuan-lite、
|
||||
- hunyuan-standard
|
||||
- hunyuan-standard-256K
|
||||
- hunyuan-pro
|
||||
@@ -239,7 +233,6 @@ class ChatHunyuan(BaseChatModel):
|
||||
chunk = _convert_delta_to_message_chunk(
|
||||
choice["Delta"], default_chunk_class
|
||||
)
|
||||
chunk.id = response.get("Id", "")
|
||||
default_chunk_class = chunk.__class__
|
||||
cg_chunk = ChatGenerationChunk(message=chunk)
|
||||
if run_manager:
|
||||
|
||||
@@ -1,23 +1,9 @@
|
||||
"""OctoAI Endpoints chat wrapper. Relies heavily on ChatOpenAI."""
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Literal,
|
||||
Optional,
|
||||
Sequence,
|
||||
Type,
|
||||
Union,
|
||||
)
|
||||
from typing import Dict
|
||||
|
||||
from langchain_core.language_models import LanguageModelInput
|
||||
from langchain_core.messages import BaseMessage
|
||||
from langchain_core.pydantic_v1 import Field, SecretStr
|
||||
from langchain_core.runnables import Runnable
|
||||
from langchain_core.tools import BaseTool
|
||||
from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env, pre_init
|
||||
from langchain_core.utils.function_calling import convert_to_openai_tool
|
||||
|
||||
from langchain_community.chat_models.openai import ChatOpenAI
|
||||
from langchain_community.utils.openai import is_openai_v1
|
||||
@@ -106,53 +92,3 @@ class ChatOctoAI(ChatOpenAI):
|
||||
)
|
||||
|
||||
return values
|
||||
|
||||
def bind_tools(
|
||||
self,
|
||||
tools: Sequence[Union[Dict[str, Any], Type, Callable, BaseTool]],
|
||||
*,
|
||||
tool_choice: Optional[
|
||||
Union[dict, str, Literal["auto", "none", "required", "any"], bool]
|
||||
] = None,
|
||||
strict: Optional[bool] = None,
|
||||
**kwargs: Any,
|
||||
) -> Runnable[LanguageModelInput, BaseMessage]:
|
||||
"""Imitating bind_tool method from langchain_openai.ChatOpenAI"""
|
||||
|
||||
formatted_tools = [
|
||||
convert_to_openai_tool(tool, strict=strict) for tool in tools
|
||||
]
|
||||
if tool_choice:
|
||||
if isinstance(tool_choice, str):
|
||||
# tool_choice is a tool/function name
|
||||
if tool_choice not in ("auto", "none", "any", "required"):
|
||||
tool_choice = {
|
||||
"type": "function",
|
||||
"function": {"name": tool_choice},
|
||||
}
|
||||
# 'any' is not natively supported by OpenAI API.
|
||||
# We support 'any' since other models use this instead of 'required'.
|
||||
if tool_choice == "any":
|
||||
tool_choice = "required"
|
||||
elif isinstance(tool_choice, bool):
|
||||
tool_choice = "required"
|
||||
elif isinstance(tool_choice, dict):
|
||||
tool_names = [
|
||||
formatted_tool["function"]["name"]
|
||||
for formatted_tool in formatted_tools
|
||||
]
|
||||
if not any(
|
||||
tool_name == tool_choice["function"]["name"]
|
||||
for tool_name in tool_names
|
||||
):
|
||||
raise ValueError(
|
||||
f"Tool choice {tool_choice} was specified, but the only "
|
||||
f"provided tools were {tool_names}."
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Unrecognized tool_choice type. Expected str, bool or dict. "
|
||||
f"Received: {tool_choice}"
|
||||
)
|
||||
kwargs["tool_choice"] = tool_choice
|
||||
return super().bind(tools=formatted_tools, **kwargs)
|
||||
|
||||
@@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
@@ -147,33 +146,6 @@ def _convert_delta_to_message_chunk(
|
||||
return default_class(content=content) # type: ignore[call-arg]
|
||||
|
||||
|
||||
def _update_token_usage(
|
||||
overall_token_usage: Union[int, dict], new_usage: Union[int, dict]
|
||||
) -> Union[int, dict]:
|
||||
# Token usage is either ints or dictionaries
|
||||
# `reasoning_tokens` is nested inside `completion_tokens_details`
|
||||
if isinstance(new_usage, int):
|
||||
if not isinstance(overall_token_usage, int):
|
||||
raise ValueError(
|
||||
f"Got different types for token usage: "
|
||||
f"{type(new_usage)} and {type(overall_token_usage)}"
|
||||
)
|
||||
return new_usage + overall_token_usage
|
||||
elif isinstance(new_usage, dict):
|
||||
if not isinstance(overall_token_usage, dict):
|
||||
raise ValueError(
|
||||
f"Got different types for token usage: "
|
||||
f"{type(new_usage)} and {type(overall_token_usage)}"
|
||||
)
|
||||
return {
|
||||
k: _update_token_usage(overall_token_usage.get(k, 0), v)
|
||||
for k, v in new_usage.items()
|
||||
}
|
||||
else:
|
||||
warnings.warn(f"Unexpected type for token usage: {type(new_usage)}")
|
||||
return new_usage
|
||||
|
||||
|
||||
@deprecated(
|
||||
since="0.0.10", removal="1.0", alternative_import="langchain_openai.ChatOpenAI"
|
||||
)
|
||||
@@ -402,9 +374,7 @@ class ChatOpenAI(BaseChatModel):
|
||||
if token_usage is not None:
|
||||
for k, v in token_usage.items():
|
||||
if k in overall_token_usage:
|
||||
overall_token_usage[k] = _update_token_usage(
|
||||
overall_token_usage[k], v
|
||||
)
|
||||
overall_token_usage[k] += v
|
||||
else:
|
||||
overall_token_usage[k] = v
|
||||
if system_fingerprint is None:
|
||||
@@ -433,8 +403,6 @@ class ChatOpenAI(BaseChatModel):
|
||||
if len(chunk["choices"]) == 0:
|
||||
continue
|
||||
choice = chunk["choices"][0]
|
||||
if choice["delta"] is None:
|
||||
continue
|
||||
chunk = _convert_delta_to_message_chunk(
|
||||
choice["delta"], default_chunk_class
|
||||
)
|
||||
@@ -527,8 +495,6 @@ class ChatOpenAI(BaseChatModel):
|
||||
if len(chunk["choices"]) == 0:
|
||||
continue
|
||||
choice = chunk["choices"][0]
|
||||
if choice["delta"] is None:
|
||||
continue
|
||||
chunk = _convert_delta_to_message_chunk(
|
||||
choice["delta"], default_chunk_class
|
||||
)
|
||||
|
||||
@@ -104,8 +104,6 @@ class CSVLoader(BaseLoader):
|
||||
csv_args: Optional[Dict] = None,
|
||||
encoding: Optional[str] = None,
|
||||
autodetect_encoding: bool = False,
|
||||
*,
|
||||
content_columns: Sequence[str] = (),
|
||||
):
|
||||
"""
|
||||
|
||||
@@ -118,8 +116,6 @@ class CSVLoader(BaseLoader):
|
||||
Optional. Defaults to None.
|
||||
encoding: The encoding of the CSV file. Optional. Defaults to None.
|
||||
autodetect_encoding: Whether to try to autodetect the file encoding.
|
||||
content_columns: A sequence of column names to use for the document content.
|
||||
If not present, use all columns that are not part of the metadata.
|
||||
"""
|
||||
self.file_path = file_path
|
||||
self.source_column = source_column
|
||||
@@ -127,7 +123,6 @@ class CSVLoader(BaseLoader):
|
||||
self.encoding = encoding
|
||||
self.csv_args = csv_args or {}
|
||||
self.autodetect_encoding = autodetect_encoding
|
||||
self.content_columns = content_columns
|
||||
|
||||
def lazy_load(self) -> Iterator[Document]:
|
||||
try:
|
||||
@@ -168,11 +163,7 @@ class CSVLoader(BaseLoader):
|
||||
if isinstance(v, str) else ','.join(map(str.strip, v))
|
||||
if isinstance(v, list) else v}"""
|
||||
for k, v in row.items()
|
||||
if (
|
||||
k in self.content_columns
|
||||
if self.content_columns
|
||||
else k not in self.metadata_columns
|
||||
)
|
||||
if k not in self.metadata_columns
|
||||
)
|
||||
metadata = {"source": source, "row": i}
|
||||
for col in self.metadata_columns:
|
||||
|
||||
@@ -206,10 +206,7 @@ class GithubFileLoader(BaseGitHubLoader, ABC):
|
||||
]
|
||||
|
||||
def get_file_content_by_path(self, path: str) -> str:
|
||||
queryparams = f"?ref={self.branch}" if self.branch else ""
|
||||
base_url = (
|
||||
f"{self.github_api_url}/repos/{self.repo}/contents/{path}{queryparams}"
|
||||
)
|
||||
base_url = f"{self.github_api_url}/repos/{self.repo}/contents/{path}"
|
||||
response = requests.get(base_url, headers=self.headers)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ MIN_VERSION = "0.2.0"
|
||||
|
||||
class FastEmbedEmbeddings(BaseModel, Embeddings):
|
||||
"""Qdrant FastEmbedding models.
|
||||
|
||||
FastEmbed is a lightweight, fast, Python library built for embedding generation.
|
||||
See more documentation at:
|
||||
* https://github.com/qdrant/fastembed/
|
||||
|
||||
@@ -67,19 +67,6 @@ class HuggingFaceEmbeddings(BaseModel, Embeddings):
|
||||
def __init__(self, **kwargs: Any):
|
||||
"""Initialize the sentence_transformer."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if "model_name" not in kwargs:
|
||||
since = "0.2.16"
|
||||
removal = "0.4.0"
|
||||
warn_deprecated(
|
||||
since=since,
|
||||
removal=removal,
|
||||
message=f"Default values for {self.__class__.__name__}.model_name"
|
||||
+ f" were deprecated in LangChain {since} and will be removed in"
|
||||
+ f" {removal}. Explicitly pass a model_name to the"
|
||||
+ f" {self.__class__.__name__} constructor instead.",
|
||||
)
|
||||
|
||||
try:
|
||||
import sentence_transformers
|
||||
|
||||
@@ -172,19 +159,6 @@ class HuggingFaceInstructEmbeddings(BaseModel, Embeddings):
|
||||
def __init__(self, **kwargs: Any):
|
||||
"""Initialize the sentence_transformer."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if "model_name" not in kwargs:
|
||||
since = "0.2.16"
|
||||
removal = "0.4.0"
|
||||
warn_deprecated(
|
||||
since=since,
|
||||
removal=removal,
|
||||
message=f"Default values for {self.__class__.__name__}.model_name"
|
||||
+ f" were deprecated in LangChain {since} and will be removed in"
|
||||
+ f" {removal}. Explicitly pass a model_name to the"
|
||||
+ f" {self.__class__.__name__} constructor instead.",
|
||||
)
|
||||
|
||||
try:
|
||||
from InstructorEmbedding import INSTRUCTOR
|
||||
|
||||
@@ -257,7 +231,7 @@ class HuggingFaceBgeEmbeddings(BaseModel, Embeddings):
|
||||
|
||||
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
||||
|
||||
model_name = "BAAI/bge-large-en-v1.5"
|
||||
model_name = "BAAI/bge-large-en"
|
||||
model_kwargs = {'device': 'cpu'}
|
||||
encode_kwargs = {'normalize_embeddings': True}
|
||||
hf = HuggingFaceBgeEmbeddings(
|
||||
@@ -305,19 +279,6 @@ class HuggingFaceBgeEmbeddings(BaseModel, Embeddings):
|
||||
def __init__(self, **kwargs: Any):
|
||||
"""Initialize the sentence_transformer."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if "model_name" not in kwargs:
|
||||
since = "0.2.5"
|
||||
removal = "0.4.0"
|
||||
warn_deprecated(
|
||||
since=since,
|
||||
removal=removal,
|
||||
message=f"Default values for {self.__class__.__name__}.model_name"
|
||||
+ f" were deprecated in LangChain {since} and will be removed in"
|
||||
+ f" {removal}. Explicitly pass a model_name to the"
|
||||
+ f" {self.__class__.__name__} constructor instead.",
|
||||
)
|
||||
|
||||
try:
|
||||
import sentence_transformers
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ class TinyAsyncOpenAIInfinityEmbeddingClient: #: :meta private:
|
||||
f"Infinity returned an unexpected response with status "
|
||||
f"{response.status}: {response.text}"
|
||||
)
|
||||
embedding = (await response.json())["data"]
|
||||
embedding = (await response.json())["embeddings"]
|
||||
return [e["embedding"] for e in embedding]
|
||||
|
||||
async def aembed(self, model: str, texts: List[str]) -> List[List[float]]:
|
||||
@@ -313,7 +313,7 @@ class TinyAsyncOpenAIInfinityEmbeddingClient: #: :meta private:
|
||||
*[
|
||||
self._async_request(
|
||||
session=session,
|
||||
kwargs=self._kwargs_post_request(model=model, texts=t),
|
||||
**self._kwargs_post_request(model=model, texts=t),
|
||||
)
|
||||
for t in perm_texts_batched
|
||||
]
|
||||
|
||||
@@ -57,9 +57,6 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
|
||||
verbose: bool = Field(True, alias="verbose")
|
||||
"""Print verbose output to stderr."""
|
||||
|
||||
device: Optional[str] = Field(None, alias="device")
|
||||
"""Device type to use and pass to the model"""
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
@@ -78,7 +75,6 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
|
||||
"n_threads",
|
||||
"n_batch",
|
||||
"verbose",
|
||||
"device",
|
||||
]
|
||||
model_params = {k: values[k] for k in model_param_names}
|
||||
# For backwards compatibility, only include if non-null.
|
||||
@@ -112,8 +108,8 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
|
||||
Returns:
|
||||
List of embeddings, one for each text.
|
||||
"""
|
||||
embeddings = self.client.create_embedding(texts)
|
||||
return [list(map(float, e["embedding"])) for e in embeddings["data"]]
|
||||
embeddings = [self.client.embed(text) for text in texts]
|
||||
return [list(map(float, e)) for e in embeddings]
|
||||
|
||||
def embed_query(self, text: str) -> List[float]:
|
||||
"""Embed a query using the Llama model.
|
||||
|
||||
@@ -303,7 +303,7 @@ class OpenVINOBgeEmbeddings(OpenVINOEmbeddings):
|
||||
|
||||
from langchain_community.embeddings import OpenVINOBgeEmbeddings
|
||||
|
||||
model_name = "BAAI/bge-large-en-v1.5"
|
||||
model_name = "BAAI/bge-large-en"
|
||||
model_kwargs = {'device': 'CPU'}
|
||||
encode_kwargs = {'normalize_embeddings': True}
|
||||
ov = OpenVINOBgeEmbeddings(
|
||||
|
||||
@@ -1,161 +1,3 @@
|
||||
"""**Graph Vector Store**
|
||||
|
||||
Sometimes embedding models don’t capture all the important relationships between
|
||||
documents.
|
||||
Graph Vector Stores are an extension to both vector stores and retrievers that allow
|
||||
documents to be explicitly connected to each other.
|
||||
|
||||
Graph vector store retrievers use both vector similarity and links to find documents
|
||||
related to an unstructured query.
|
||||
|
||||
Graphs allow linking between documents.
|
||||
Each document identifies tags that link to and from it.
|
||||
For example, a paragraph of text may be linked to URLs based on the anchor tags in
|
||||
it's content and linked from the URL(s) it is published at.
|
||||
|
||||
Link extractors can be used to extract links from documents.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
graph_vector_store = CassandraGraphVectorStore()
|
||||
link_extractor = HtmlLinkExtractor()
|
||||
links = link_extractor.extract_one(HtmlInput(document.page_content, "http://mysite"))
|
||||
add_links(document, links)
|
||||
graph_vector_store.add_document(document)
|
||||
|
||||
***********
|
||||
Get started
|
||||
***********
|
||||
|
||||
We chunk the State of the Union text and split it into documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
raw_documents = TextLoader("state_of_the_union.txt").load()
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
Links can be added to documents manually but it's easier to use a
|
||||
:class:`~langchain_community.graph_vectorstores.extractors.LinkExtractor`.
|
||||
Several common link extractors are available and you can build your own.
|
||||
For this guide, we'll use the
|
||||
:class:`~langchain_community.graph_vectorstores.extractors.KeybertLinkExtractor`
|
||||
which uses the KeyBERT model to tag documents with keywords and uses these keywords to
|
||||
create links between documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_community.graph_vectorstores.extractors import KeybertLinkExtractor
|
||||
from langchain_community.graph_vectorstores.links import add_links
|
||||
|
||||
extractor = KeybertLinkExtractor()
|
||||
|
||||
for doc in documents:
|
||||
add_links(doc, extractor.extract_one(doc))
|
||||
|
||||
***********************************************
|
||||
Create the graph vector store and add documents
|
||||
***********************************************
|
||||
|
||||
We'll use an Apache Cassandra or Astra DB database as an example.
|
||||
We create a :class:`~langchain_community.graph_vectorstores.CassandraGraphVectorStore`
|
||||
from the documents and an :class:`~langchain_openai.OpenAIEmbeddings` model.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cassio
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
|
||||
# Initialize cassio and the Cassandra session from the environment variables
|
||||
cassio.init(auto=True)
|
||||
|
||||
store = CassandraGraphVectorStore.from_documents(
|
||||
embedding=OpenAIEmbeddings(),
|
||||
documents=documents,
|
||||
)
|
||||
|
||||
*****************
|
||||
Similarity search
|
||||
*****************
|
||||
|
||||
If we don't traverse the graph, a graph vector store behaves like a regular vector
|
||||
store.
|
||||
So all methods available in a vector store are also available in a graph vector store.
|
||||
The :meth:`~langchain_community.graph_vectorstores.base.GraphVectorStore.similarity_search`
|
||||
method returns documents similar to a query without considering
|
||||
the links between documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
docs = store.similarity_search(
|
||||
"What did the president say about Ketanji Brown Jackson?"
|
||||
)
|
||||
|
||||
****************
|
||||
Traversal search
|
||||
****************
|
||||
|
||||
The :meth:`~langchain_community.graph_vectorstores.base.GraphVectorStore.traversal_search`
|
||||
method returns documents similar to a query considering the links
|
||||
between documents. It first does a similarity search and then traverses the graph to
|
||||
find linked documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
docs = list(
|
||||
store.traversal_search("What did the president say about Ketanji Brown Jackson?")
|
||||
)
|
||||
|
||||
*************
|
||||
Async methods
|
||||
*************
|
||||
|
||||
The graph vector store has async versions of the methods prefixed with ``a``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
docs = [
|
||||
doc
|
||||
async for doc in store.atraversal_search(
|
||||
"What did the president say about Ketanji Brown Jackson?"
|
||||
)
|
||||
]
|
||||
|
||||
****************************
|
||||
Graph vector store retriever
|
||||
****************************
|
||||
|
||||
The graph vector store can be converted to a retriever.
|
||||
It is similar to the vector store retriever but it also has traversal search methods
|
||||
such as ``traversal`` and ``mmr_traversal``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
retriever = store.as_retriever(search_type="mmr_traversal")
|
||||
docs = retriever.invoke("What did the president say about Ketanji Brown Jackson?")
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
from langchain_community.graph_vectorstores.base import (
|
||||
GraphVectorStore,
|
||||
GraphVectorStoreRetriever,
|
||||
Node,
|
||||
)
|
||||
from langchain_community.graph_vectorstores.cassandra import CassandraGraphVectorStore
|
||||
from langchain_community.graph_vectorstores.links import (
|
||||
Link,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"GraphVectorStore",
|
||||
"GraphVectorStoreRetriever",
|
||||
"Node",
|
||||
"Link",
|
||||
"CassandraGraphVectorStore",
|
||||
]
|
||||
__all__ = ["CassandraGraphVectorStore"]
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
from langchain_core.graph_vectorstores.base import (
|
||||
GraphVectorStore,
|
||||
GraphVectorStoreRetriever,
|
||||
Node,
|
||||
)
|
||||
|
||||
__all__ = ["GraphVectorStore", "GraphVectorStoreRetriever", "Node"]
|
||||
@@ -14,117 +14,7 @@ GLiNERInput = Union[str, Document]
|
||||
|
||||
@beta()
|
||||
class GLiNERLinkExtractor(LinkExtractor[GLiNERInput]):
|
||||
"""Link documents with common named entities using `GLiNER`_.
|
||||
|
||||
`GLiNER`_ is a Named Entity Recognition (NER) model capable of identifying any
|
||||
entity type using a bidirectional transformer encoder (BERT-like).
|
||||
|
||||
The ``GLiNERLinkExtractor`` uses GLiNER to create links between documents that
|
||||
have named entities in common.
|
||||
|
||||
Example::
|
||||
|
||||
extractor = GLiNERLinkExtractor(
|
||||
labels=["Person", "Award", "Date", "Competitions", "Teams"]
|
||||
)
|
||||
results = extractor.extract_one("some long text...")
|
||||
|
||||
.. _GLiNER: https://github.com/urchade/GLiNER
|
||||
|
||||
.. seealso::
|
||||
|
||||
- :mod:`How to use a graph vector store <langchain_community.graph_vectorstores>`
|
||||
- :class:`How to create links between documents <langchain_core.graph_vectorstores.links.Link>`
|
||||
|
||||
How to link Documents on common named entities
|
||||
==============================================
|
||||
|
||||
Preliminaries
|
||||
-------------
|
||||
|
||||
Install the ``gliner`` package:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install -q langchain_community gliner
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
We load the ``state_of_the_union.txt`` file, chunk it, then for each chunk we
|
||||
extract named entity links and add them to the chunk.
|
||||
|
||||
Using extract_one()
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
We can use :meth:`extract_one` on a document to get the links and add the links
|
||||
to the document metadata with
|
||||
:meth:`~langchain_core.graph_vectorstores.links.add_links`::
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
from langchain_community.graph_vectorstores.extractors import GLiNERLinkExtractor
|
||||
from langchain_core.graph_vectorstores.links import add_links
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
loader = TextLoader("state_of_the_union.txt")
|
||||
raw_documents = loader.load()
|
||||
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
ner_extractor = GLiNERLinkExtractor(["Person", "Topic"])
|
||||
for document in documents:
|
||||
links = ner_extractor.extract_one(document)
|
||||
add_links(document, links)
|
||||
|
||||
print(documents[0].metadata)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
{'source': 'state_of_the_union.txt', 'links': [Link(kind='entity:Person', direction='bidir', tag='President Zelenskyy'), Link(kind='entity:Person', direction='bidir', tag='Vladimir Putin')]}
|
||||
|
||||
Using LinkExtractorTransformer
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Using the :class:`~langchain_community.graph_vectorstores.extractors.keybert_link_extractor.LinkExtractorTransformer`,
|
||||
we can simplify the link extraction::
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_community.graph_vectorstores.extractors import (
|
||||
GLiNERLinkExtractor,
|
||||
LinkExtractorTransformer,
|
||||
)
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
loader = TextLoader("state_of_the_union.txt")
|
||||
raw_documents = loader.load()
|
||||
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
ner_extractor = GLiNERLinkExtractor(["Person", "Topic"])
|
||||
transformer = LinkExtractorTransformer([ner_extractor])
|
||||
documents = transformer.transform_documents(documents)
|
||||
|
||||
print(documents[0].metadata)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
{'source': 'state_of_the_union.txt', 'links': [Link(kind='entity:Person', direction='bidir', tag='President Zelenskyy'), Link(kind='entity:Person', direction='bidir', tag='Vladimir Putin')]}
|
||||
|
||||
The documents with named entity links can then be added to a :class:`~langchain_core.graph_vectorstores.base.GraphVectorStore`::
|
||||
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
|
||||
store = CassandraGraphVectorStore.from_documents(documents=documents, embedding=...)
|
||||
|
||||
Args:
|
||||
labels: List of kinds of entities to extract.
|
||||
kind: Kind of links to produce with this extractor.
|
||||
model: GLiNER model to use.
|
||||
extract_kwargs: Keyword arguments to pass to GLiNER.
|
||||
""" # noqa: E501
|
||||
"""Link documents with common named entities using GLiNER <https://github.com/urchade/GLiNER>."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -134,6 +24,23 @@ class GLiNERLinkExtractor(LinkExtractor[GLiNERInput]):
|
||||
model: str = "urchade/gliner_mediumv2.1",
|
||||
extract_kwargs: Optional[Dict[str, Any]] = None,
|
||||
):
|
||||
"""Extract keywords using GLiNER.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
extractor = GLiNERLinkExtractor(
|
||||
labels=["Person", "Award", "Date", "Competitions", "Teams"]
|
||||
)
|
||||
results = extractor.extract_one("some long text...")
|
||||
|
||||
Args:
|
||||
labels: List of kinds of entities to extract.
|
||||
kind: Kind of links to produce with this extractor.
|
||||
model: GLiNER model to use.
|
||||
extract_kwargs: Keyword arguments to pass to GLiNER.
|
||||
"""
|
||||
try:
|
||||
from gliner import GLiNER
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user