Skip to content

Commit

Permalink
Use langchain-astradb package
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Mar 11, 2024
1 parent c90d88f commit 40287b8
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 78 deletions.
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/dev-environment.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ To install the `load_dotenv` package, run `pip install python-dotenv`.
----
import os
from dotenv import load_dotenv
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
load_dotenv()
Expand All @@ -159,7 +159,7 @@ OPEN_AI_API_KEY = os.environ.get("OPENAI_API_KEY")
ASTRA_DB_COLLECTION = os.environ.get("ASTRA_DB_COLLECTION")
embedding = OpenAIEmbeddings()
vstore = AstraDB(
vstore = AstraDBVectorStore(
embedding=embedding,
collection_name="test",
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/migration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import os
from datasets import load_dataset
from dotenv import load_dotenv
from langchain_community.document_loaders import PyPDFDirectoryLoader
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core import Document
Expand All @@ -52,7 +52,7 @@ OPEN_AI_API_KEY = os.environ.get("OPENAI_API_KEY")
ASTRA_DB_COLLECTION = os.environ.get("ASTRA_DB_COLLECTION")
embedding = OpenAIEmbeddings()
vstore = AstraDB(
vstore = AstraDBVectorStore(
embedding=embedding,
collection_name="test3",
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/quickstart.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ With your environment set up, you're ready to create a RAG workflow in Python.
import os
from dotenv import load_dotenv
from datasets import load_dataset
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core import Document
from langchain.prompts import ChatPromptTemplate
Expand All @@ -145,7 +145,7 @@ ASTRA_DB_COLLECTION = os.environ.get("ASTRA_DB_COLLECTION")
[source,python]
----
embedding = OpenAIEmbeddings()
vstore = AstraDB(
vstore = AstraDBVectorStore(
embedding=embedding,
collection_name="test",
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
Expand Down Expand Up @@ -244,7 +244,7 @@ Python::
import os
from dotenv import load_dotenv
from datasets import load_dataset
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core import Document
from langchain_core.prompts import ChatPromptTemplate
Expand All @@ -260,7 +260,7 @@ OPEN_AI_API_KEY = os.environ.get("OPENAI_API_KEY")
ASTRA_DB_COLLECTION = os.environ.get("ASTRA_DB_COLLECTION")
embedding = OpenAIEmbeddings()
vstore = AstraDB(
vstore = AstraDBVectorStore(
embedding=embedding,
collection_name="test",
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/default-architecture/pages/retrieval.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Python::
----
import os
from dotenv import load_dotenv
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
Expand All @@ -27,7 +27,7 @@ load_dotenv()
OPEN_AI_API_KEY = os.environ["OPENAI_API_KEY"]
vstore = AstraDB(
vstore = AstraDBVectorStore(
embedding=OpenAIEmbeddings(openai_api_key=OPEN_AI_API_KEY),
collection_name="test",
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/default-architecture/pages/storing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ This code embeds the loaded `Documents` from the xref:splitting.adoc[] example a
----
import os
from dotenv import load_dotenv
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
load_dotenv()
ASTRA_DB_COLLECTION = os.environ.get("ASTRA_DB_COLLECTION")
embedding = OpenAIEmbeddings()
vstore = AstraDB(
vstore = AstraDBVectorStore(
embedding=embedding,
collection_name="test",
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/examples/pages/advanced-rag.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ from langchain_openai import OpenAIEmbeddings
from langchain_community.retrievers import ParentDocumentRetriever
from langchain_community.storage import InMemoryStore
from langchain.text_splitter import TokenTextSplitter
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
----
+
. The two advanced RAG techniques require different dependencies.
Expand Down Expand Up @@ -156,7 +156,7 @@ model = ChatOpenAI(openai_api_key=openai_api_key, model_name="gpt-3.5-turbo", te
embedding = OpenAIEmbeddings(openai_api_key=openai_api_key)
# Initialize a vector store for storing the child chunks
vstore = AstraDB(
vstore = AstraDBVectorStore(
collection_name=collection_name,
embedding=embedding,
token=astra_token,
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/examples/pages/flare.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pip install ragstack-ai
----
import os
from dotenv import load_dotenv
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_community.document_loaders import TextLoader
from langchain.globals import set_verbose
Expand All @@ -53,7 +53,7 @@ from langchain.chains.flare.base import QuestionGeneratorChain
[source,python]
----
embedding = OpenAIEmbeddings()
vstore = AstraDB(
vstore = AstraDBVectorStore(
collection_name=collection,
embedding=embedding,
token=astra_token,
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/examples/pages/langchain-evaluation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pip install ragstack-ai langchain[openai]
import os
from dotenv import load_dotenv
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_community.document_loaders import TextLoader
from langchain_community.document_loaders import PyPDFLoader
from langchain.evaluation import EvaluatorType
Expand All @@ -55,7 +55,7 @@ from langchain.chains import RetrievalQA
[source,python]
----
embedding = OpenAIEmbeddings(openai_api_key=openai_api_key)
vstore = AstraDB(
vstore = AstraDBVectorStore(
collection_name=collection,
embedding=embedding,
token=astra_token,
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/examples/pages/langchain-unstructured-astra.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import os
import requests
from dotenv import load_dotenv
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_core.documents import Document
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
Expand Down Expand Up @@ -144,7 +144,7 @@ See the Colab notebook linked at the top of this page for a more detailed invest
+
[source,python]
----
astra_db_store = AstraDB(
astra_db_store = AstraDBVectorStore(
collection_name="langchain_unstructured",
embedding=OpenAIEmbeddings(),
token=os.getenv("ASTRA_DB_APPLICATION_TOKEN"),
Expand Down Expand Up @@ -236,7 +236,7 @@ import requests
from dotenv import load_dotenv
from langchain_community.document_loaders import unstructured
from langchain_community.vectorstores import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain_core.documents import Document
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
Expand Down Expand Up @@ -269,7 +269,7 @@ elements = unstructured.get_elements_from_api(
pdf_infer_table_structure=True,
)
astra_db_store = AstraDB(
astra_db_store = AstraDBVectorStore(
collection_name="langchain_unstructured",
embedding=OpenAIEmbeddings(),
token=os.getenv("ASTRA_DB_APPLICATION_TOKEN"),
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/examples/pages/nvidia_embeddings.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ embedding = NVIDIAEmbeddings(
[source,python]
----
import os
from langchain.vectorstores.astradb import AstraDB
from langchain_astradb import AstraDBVectorStore
vstore = AstraDB(
vstore = AstraDBVectorStore(
collection_name=collection,
embedding=embedding,
token=os.getenv("ASTRA_DB_APPLICATION_TOKEN"),
Expand Down Expand Up @@ -194,7 +194,7 @@ vstore.delete_collection()
----
from datasets import load_dataset
from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings, ChatNVIDIA
from langchain.vectorstores.astradb import AstraDB
from langchain_astradb import AstraDBVectorStore
from langchain.schema import Document
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI
Expand All @@ -210,7 +210,7 @@ embedding = NVIDIAEmbeddings(nvidia_api_key=nvidia_api_key, model="nvolveqa_40k"
collection_name = "test"
astra_token = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
astra_api_endpoint = os.getenv("ASTRA_DB_API_ENDPOINT")
vstore = AstraDB(collection_name=collection_name, embedding=embedding,
vstore = AstraDBVectorStore(collection_name=collection_name, embedding=embedding,
token=astra_token, api_endpoint=astra_api_endpoint)
print("Astra vector store configured")
Expand Down
4 changes: 2 additions & 2 deletions evaluation/langchain_trulens_full.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.vectorstores.astradb import AstraDB\n",
"from langchain_astradb import AstraDBVectorStore\n",
"import os\n",
"\n",
"astra_db_vstore = AstraDB(\n",
"astra_db_vstore = AstraDBVectorStore(\n",
" collection_name=astra_db_collection_name,\n",
" embedding=open_ai_embeddings,\n",
" token=os.getenv(\"ASTRA_DB_TOKEN\"),\n",
Expand Down
4 changes: 2 additions & 2 deletions evaluation/tru_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from langchain_community.chat_models import AzureChatOpenAI
from langchain_community.embeddings import AzureOpenAIEmbeddings
from langchain.vectorstores.astradb import AstraDB
from langchain_astradb import AstraDBVectorStore as LangChainAstraDBVectorStore

# this code assumes the following env vars exist in a .env file:
#
Expand Down Expand Up @@ -171,7 +171,7 @@ def get_azure_embeddings_model(framework: Framework):

def get_astra_vector_store(framework: Framework, collection_name: str):
if framework == Framework.LANG_CHAIN:
return AstraDB(
return LangChainAstraDBVectorStore(
collection_name=collection_name,
embedding=get_azure_embeddings_model(framework),
token=os.getenv("ASTRA_DB_TOKEN"),
Expand Down
32 changes: 16 additions & 16 deletions examples/notebooks/FLARE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@
}
],
"source": [
"from langchain.vectorstores.astradb import AstraDB\n",
"from langchain_astradb import AstraDBVectorStore\n",
"from langchain.embeddings import OpenAIEmbeddings\n",
"import os\n",
"\n",
"# Configure your embedding model and vector store\n",
"embedding = OpenAIEmbeddings()\n",
"vstore = AstraDB(\n",
"vstore = AstraDBVectorStore(\n",
" collection_name=collection,\n",
" embedding=embedding,\n",
" token=os.environ[\"ASTRA_DB_TOKEN\"],\n",
Expand Down Expand Up @@ -270,33 +270,33 @@
"text": [
"\n",
"\n",
"\u001b[1m> Entering new FlareChain chain...\u001b[0m\n",
"\u001b[36;1m\u001b[1;3mCurrent Response: \u001b[0m\n",
"\u001B[1m> Entering new FlareChain chain...\u001B[0m\n",
"\u001B[36;1m\u001B[1;3mCurrent Response: \u001B[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3mRespond to the user message using any relevant context. If context is provided, you should ground your answer in that context. Once you're done responding return FINISHED.\n",
"\u001B[32;1m\u001B[1;3mRespond to the user message using any relevant context. If context is provided, you should ground your answer in that context. Once you're done responding return FINISHED.\n",
"\n",
">>> CONTEXT: \n",
">>> USER INPUT: Who is Luchesi in relation to Antonio?\n",
">>> RESPONSE: \u001b[0m\n",
">>> RESPONSE: \u001B[0m\n",
"\n",
"\n",
"\u001b[1m> Entering new QuestionGeneratorChain chain...\u001b[0m\n",
"\u001B[1m> Entering new QuestionGeneratorChain chain...\u001B[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3mGiven a user input and an existing partial response as context, ask a question to which the answer is the given term/entity/phrase:\n",
"\u001B[32;1m\u001B[1;3mGiven a user input and an existing partial response as context, ask a question to which the answer is the given term/entity/phrase:\n",
"\n",
">>> USER INPUT: Who is Luchesi in relation to Antonio?\n",
">>> EXISTING PARTIAL RESPONSE: \n",
"Luchesi is a rival of Antonio's. He is a wealthy merchant who is jealous of Antonio's success. FINISHED\n",
"\n",
"The question to which the answer is the term/entity/phrase \" jealous of Antonio\" is:\u001b[0m\n",
"The question to which the answer is the term/entity/phrase \" jealous of Antonio\" is:\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"\u001b[33;1m\u001b[1;3mGenerated Questions: ['Why is Luchesi considered a rival of Antonio?']\u001b[0m\n",
"\u001B[1m> Finished chain.\u001B[0m\n",
"\u001B[33;1m\u001B[1;3mGenerated Questions: ['Why is Luchesi considered a rival of Antonio?']\u001B[0m\n",
"\n",
"\n",
"\u001b[1m> Entering new _OpenAIResponseChain chain...\u001b[0m\n",
"\u001B[1m> Entering new _OpenAIResponseChain chain...\u001B[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3mRespond to the user message using any relevant context. If context is provided, you should ground your answer in that context. Once you're done responding return FINISHED.\n",
"\u001B[32;1m\u001B[1;3mRespond to the user message using any relevant context. If context is provided, you should ground your answer in that context. Once you're done responding return FINISHED.\n",
"\n",
">>> CONTEXT: The thousand injuries of Fortunato I had borne as I best could, but\n",
"when he ventured upon insult, I vowed revenge. You, who so well know\n",
Expand Down Expand Up @@ -620,11 +620,11 @@
"him who clamoured. I re-echoed--I aided--I surpassed them in volume\n",
"and in strength. I did this, and the clamourer grew still.\n",
">>> USER INPUT: Who is Luchesi in relation to Antonio?\n",
">>> RESPONSE: \u001b[0m\n",
">>> RESPONSE: \u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"\u001B[1m> Finished chain.\u001B[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
"\u001B[1m> Finished chain.\u001B[0m\n"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/advancedRAG.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@
"from langchain.retrievers import ParentDocumentRetriever\n",
"from langchain.storage import InMemoryStore\n",
"from langchain.text_splitter import TokenTextSplitter\n",
"from langchain.vectorstores.astradb import AstraDB\n",
"from langchain_astradb import AstraDBVectorStore\n",
"import os\n",
"\n",
"# Initialize the models\n",
"model = ChatOpenAI(model_name=\"gpt-3.5-turbo\", temperature=0.1)\n",
"embedding = OpenAIEmbeddings()\n",
"\n",
"# Initialize a vector store for storing the child chunks\n",
"vstore = AstraDB(\n",
"vstore = AstraDBVectorStore(\n",
" collection_name=\"advancedRAG\",\n",
" embedding=embedding,\n",
" token=os.environ[\"ASTRA_DB_TOKEN\"],\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/astradb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.vectorstores import AstraDB"
"from langchain_astradb import AstraDBVectorStore"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
},
"outputs": [],
"source": [
"vstore = AstraDB(\n",
"vstore = AstraDBVectorStore(\n",
" embedding=embe,\n",
" collection_name=ASTRA_DB_COLLECTION,\n",
" api_endpoint=os.environ[\"ASTRA_DB_ENDPOINT\"],\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/langchain-unstructured-astra.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@
},
"outputs": [],
"source": [
"from langchain_community.vectorstores import AstraDB\n",
"from langchain_astradb import AstraDBVectorStore\n",
"from langchain_openai import OpenAIEmbeddings\n",
"\n",
"astra_db_store = AstraDB(\n",
"astra_db_store = AstraDBVectorStore(\n",
" collection_name=\"langchain_unstructured\",\n",
" embedding=OpenAIEmbeddings(),\n",
" token=os.getenv(\"ASTRA_DB_TOKEN\"),\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/langchain_evaluation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@
],
"source": [
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.vectorstores.astradb import AstraDB\n",
"from langchain_astradb import AstraDBVectorStore\n",
"import os\n",
"\n",
"# Configure your embedding model and vector store\n",
"embedding = OpenAIEmbeddings()\n",
"vstore = AstraDB(\n",
"vstore = AstraDBVectorStore(\n",
" collection_name=\"lc\",\n",
" embedding=embedding,\n",
" token=os.getenv(\"ASTRA_DB_TOKEN\"),\n",
Expand Down
Loading

0 comments on commit 40287b8

Please sign in to comment.