Skip to content

Commit

Permalink
update index creation (#28)
Browse files Browse the repository at this point in the history
* update index creation
* update llamaindex example
  • Loading branch information
rbs333 authored Aug 9, 2024
1 parent 328a1cc commit 6c591a7
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 357 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install --no-cache-dir -r requirements.txt
- name: Set Redis version
run: |
Expand All @@ -49,10 +49,5 @@ jobs:
LLAMA_CLOUD_API_KEY: ${{ secrets.LLAMA_CLOUD_API_KEY }}
GCP_REGION: ${{ secrets.GCP_REGION }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
# COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
# AZURE_OPENAI_API_KEY: ${{secrets.AZURE_OPENAI_API_KEY}}
# AZURE_OPENAI_ENDPOINT: ${{secrets.AZURE_OPENAI_ENDPOINT}}
# AZURE_OPENAI_DEPLOYMENT_NAME: ${{secrets.AZURE_OPENAI_DEPLOYMENT_NAME}}
# OPENAI_API_VERSION: ${{secrets.OPENAI_API_VERSION}}
run: |
pytest --nbval-lax python-recipes/RAG/01_redisvl.ipynb python-recipes/RAG/02_langchain.ipynb python-recipes/RAG/03_llamaindex.ipynb python-recipes/RAG/04_advanced_redisvl.ipynb python-recipes/RAG/06_ragas_evaluation.ipynb python-recipes/vector-search python-recipes/redis-intro
pytest --verbose --nbval-lax python-recipes/RAG/ python-recipes/vector-search python-recipes/redis-intro --ignore python-recipes/RAG/05_nvidia_ai_rag_redis.ipynb
289 changes: 152 additions & 137 deletions python-recipes/RAG/01_redisvl.ipynb

Large diffs are not rendered by default.

127 changes: 33 additions & 94 deletions python-recipes/RAG/02_langchain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"# Replace values below with your own if using Redis Cloud instance\n",
"REDIS_HOST = os.getenv(\"REDIS_HOST\", \"localhost\") # ex: \"redis-18374.c253.us-central1-1.gce.cloud.redislabs.com\"\n",
Expand Down Expand Up @@ -170,7 +172,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -200,22 +202,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `UnstructuredFileLoader` was deprecated in LangChain 0.2.8 and will be removed in 0.4.0. An updated version of the class exists in the langchain-unstructured package and should be used instead. To use it run `pip install -U langchain-unstructured` and import as `from langchain_unstructured import UnstructuredLoader`.\n",
" warn_deprecated(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done preprocessing. Created 180 chunks of the original pdf resources/nke-10k-2023.pdf\n"
"Done preprocessing. Created 179 chunks of the original pdf resources/nke-10k-2023.pdf\n"
]
}
],
Expand Down Expand Up @@ -249,7 +243,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand Down Expand Up @@ -414,16 +408,7 @@
"id": "_h1e-L9yZfaY",
"outputId": "fd540dd7-a0aa-4827-e001-f6d4ef603c6a"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 0.3.0. An updated version of the class exists in the langchain-huggingface package and should be used instead. To use it run `pip install -U langchain-huggingface` and import as `from langchain_huggingface import HuggingFaceEmbeddings`.\n",
" warn_deprecated(\n"
]
}
],
"outputs": [],
"source": [
"from langchain.embeddings.huggingface import HuggingFaceEmbeddings\n",
"\n",
Expand All @@ -446,7 +431,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -503,7 +488,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"id": "_Z3KpL8q1vmw"
},
Expand All @@ -520,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand Down Expand Up @@ -549,7 +534,7 @@
" 'epsilon': 0.01}]}"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -561,7 +546,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
Expand All @@ -573,10 +558,10 @@
{
"data": {
"text/plain": [
"180"
"179"
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -795,29 +780,20 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "GSpH-cur1vmz",
"outputId": "b00de5c7-1684-4e8e-c146-6d402910cdc5"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `OpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAI`.\n",
" warn_deprecated(\n"
]
}
],
"outputs": [],
"source": [
"import getpass\n",
"from langchain.llms import OpenAI\n",
"from langchain_openai import ChatOpenAI\n",
"\n",
"llm = OpenAI(openai_api_key=os.getenv(\"OPENAI_API_KEY\") or getpass.getpass(prompt=\"OpenAI API Key:\"))"
"llm = ChatOpenAI(openai_api_key=os.getenv(\"OPENAI_API_KEY\") or getpass.getpass(prompt=\"OpenAI API Key:\"))"
]
},
{
Expand All @@ -832,7 +808,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 10,
"metadata": {
"id": "yKKn2KKp3TQ4"
},
Expand Down Expand Up @@ -879,7 +855,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 11,
"metadata": {
"id": "RKNSP0zqZq98"
},
Expand Down Expand Up @@ -909,7 +885,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 13,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -919,34 +895,26 @@
"outputId": "813fffe6-3d8b-4df7-a035-c54e421c0856"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The method `Chain.__call__` was deprecated in langchain 0.1.0 and will be removed in 0.3.0. Use invoke instead.\n",
" warn_deprecated(\n"
]
},
{
"data": {
"text/plain": [
"\" Nike's revenue for the fiscal year ended May 31, 2022 was $51,217 million, while their revenue for the previous fiscal year ended May 31, 2021 was $46,710 million. This represents a 10% increase in revenue year-over-year.\""
"\"Nike's revenue last year was $46,710 million, and this year it was $51,217 million.\""
]
},
"execution_count": 19,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"What was Nike's revenue last year compared to this year??\"\n",
"res=qa(query)\n",
"res=qa.invoke(query)\n",
"res['result']"
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 14,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -959,23 +927,23 @@
{
"data": {
"text/plain": [
"' Nike offers thousands of products in athletic footwear, apparel, equipment, and accessories. Nike is part of the athletic and leisure industry, specifically the athletic footwear, apparel, and equipment industry.'"
"'Nike offers three main categories of products: footwear, apparel, and equipment. Nike is part of the athletic footwear, apparel, and equipment industry.'"
]
},
"execution_count": 20,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"How many products does Nike offer? What is the industry that Nike is part of?\"\n",
"res=qa(query)\n",
"res=qa.invoke(query)\n",
"res['result']"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 15,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -988,46 +956,17 @@
{
"data": {
"text/plain": [
"\" I cannot answer this question as it is subjective and not stated in the provided context. The financial 10k filings only provide information about the company's operations and financial performance, not its ethical practices.\""
"\"I don't know.\""
]
},
"execution_count": 21,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"Is Nike an ethical company?\"\n",
"res=qa(query)\n",
"res['result']"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"id": "kjTO0RtH1vm1",
"outputId": "f415c57b-1612-450a-db33-6b9616bff84b"
},
"outputs": [
{
"data": {
"text/plain": [
"' As of May 31, 2023, Nike had a total of 74,400 employees globally.'"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"How many employees work at Nike???\"\n",
"res=qa(query)\n",
"res=qa.invoke(query)\n",
"res['result']"
]
},
Expand Down
Loading

0 comments on commit 6c591a7

Please sign in to comment.