Skip to content

Commit 9561d9f

Browse files
authored
upgraded astra packages (#173)
* upgraded astra packages * fix tests
1 parent 4c83f98 commit 9561d9f

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

docs/examples/code-generation.ipynb

+10-2
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,11 @@
616616
{
617617
"cell_type": "code",
618618
"execution_count": null,
619-
"metadata": {},
619+
"metadata": {
620+
"tags": [
621+
"skip-execution"
622+
]
623+
},
620624
"outputs": [],
621625
"source": [
622626
"import os\n",
@@ -644,7 +648,9 @@
644648
"execution_count": null,
645649
"metadata": {
646650
"tags": [
647-
"keep_output"
651+
"skip_execution",
652+
"keep_output",
653+
"raises-exception"
648654
]
649655
},
650656
"outputs": [
@@ -699,6 +705,7 @@
699705
"execution_count": null,
700706
"metadata": {
701707
"tags": [
708+
"skip_execution",
702709
"keep_output"
703710
]
704711
},
@@ -768,6 +775,7 @@
768775
"execution_count": null,
769776
"metadata": {
770777
"tags": [
778+
"skip_execution",
771779
"keep_output"
772780
]
773781
},

packages/graph-rag-example-helpers/src/graph_rag_example_helpers/datasets/wikimultihop/load.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,16 @@ async def aload_2wikimultihop(
128128
max_tries=MAX_RETRIES,
129129
)
130130
async def add_docs(batch_docs, offset) -> None:
131-
from astrapy.exceptions import InsertManyException
131+
from astrapy.exceptions import CollectionInsertManyException
132132

133133
try:
134134
await store.aadd_documents(batch_docs)
135135
persistence.ack(offset)
136-
except InsertManyException as err:
137-
for err_desc in err.error_descriptors:
138-
if err_desc.error_code != "DOCUMENT_ALREADY_EXISTS":
139-
print(err_desc) # noqa: T201
136+
except CollectionInsertManyException as err:
137+
for exp in err.exceptions:
138+
exp_desc = str(exp)
139+
if "DOCUMENT_ALREADY_EXISTS" not in exp_desc:
140+
print(exp_desc) # noqa: T201
140141
raise
141142

142143
# We can't use asyncio.TaskGroup in 3.10. This would be simpler with that.

packages/langchain-graph-retriever/pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ graph-retriever = { workspace = true }
9595

9696
[project.optional-dependencies]
9797
astra = [
98-
"astrapy>=1.5.2",
98+
"astrapy>=2.0.0",
9999
"httpx>=0.28.1",
100-
"langchain-astradb>=0.5.3",
100+
"langchain-astradb>=0.6.0",
101101
]
102102
html = [
103103
"beautifulsoup4>=4.12.3",

packages/langchain-graph-retriever/tests/adapters/test_astra.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any
66

77
import pytest
8-
from astrapy.authentication import StaticTokenProvider
98
from graph_retriever.testing.adapter_tests import (
109
AdapterComplianceCase,
1110
AdapterComplianceSuite,
@@ -16,7 +15,9 @@
1615
from langchain_graph_retriever.adapters.astra import AstraAdapter, _queries
1716
from typing_extensions import override
1817

19-
TEST_CODEC = _DefaultVSDocumentCodec("page_content", ignore_invalid_documents=True)
18+
TEST_CODEC = _DefaultVSDocumentCodec(
19+
"page_content", ignore_invalid_documents=True, has_lexical=False
20+
)
2021

2122

2223
def create_queries(
@@ -172,7 +173,7 @@ def test_create_metadata_query_user() -> None:
172173

173174
@dataclasses.dataclass
174175
class _AstraConfig:
175-
token: StaticTokenProvider
176+
token: str
176177
keyspace: str
177178
api_endpoint: str
178179

@@ -183,16 +184,17 @@ def astra_config(enabled_stores: set[str]) -> Iterator[_AstraConfig | None]:
183184
pytest.skip("Pass --stores=astra to test Astra")
184185
return
185186

186-
from astrapy import AstraDBDatabaseAdmin
187+
from astrapy import DataAPIClient
187188
from dotenv import load_dotenv
188189

189190
load_dotenv()
190191

191-
token = StaticTokenProvider(os.environ["ASTRA_DB_APPLICATION_TOKEN"])
192+
token = os.environ["ASTRA_DB_APPLICATION_TOKEN"]
192193
keyspace = os.environ.get("ASTRA_DB_KEYSPACE", "default_keyspace")
193194
api_endpoint = os.environ["ASTRA_DB_API_ENDPOINT"]
194195

195-
admin = AstraDBDatabaseAdmin(api_endpoint=api_endpoint, token=token)
196+
my_client = DataAPIClient(token=token)
197+
admin = my_client.get_admin().get_database_admin(api_endpoint)
196198
admin.create_keyspace(keyspace)
197199

198200
# Sometimes the creation of the store fails because the keyspace isn't
@@ -281,17 +283,17 @@ def adapter(
281283
animal_docs: list[Document],
282284
astra_config: _AstraConfig,
283285
) -> Iterator["AstraAdapter"]:
284-
from astrapy.info import CollectionVectorServiceOptions
286+
from astrapy.info import VectorServiceOptions
285287
from langchain_astradb import AstraDBVectorStore
286288

287-
service = CollectionVectorServiceOptions(
289+
service_options = VectorServiceOptions(
288290
provider="nvidia",
289291
model_name="NV-Embed-QA",
290292
)
291293

292294
store = AstraDBVectorStore(
293295
collection_name="animals_vectorize",
294-
collection_vector_service_options=service,
296+
collection_vector_service_options=service_options,
295297
namespace=astra_config.keyspace,
296298
token=astra_config.token,
297299
api_endpoint=astra_config.api_endpoint,

scripts/drop-astra-keyspace.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import os
22
import sys
33

4-
from astrapy import AstraDBDatabaseAdmin
5-
from astrapy.authentication import StaticTokenProvider
4+
from astrapy import DataAPIClient
65

7-
token = StaticTokenProvider(os.environ["ASTRA_DB_APPLICATION_TOKEN"])
6+
token = os.environ["ASTRA_DB_APPLICATION_TOKEN"]
87
keyspace = os.environ.get("ASTRA_DB_KEYSPACE")
98
if keyspace is None:
109
print("No keyspace to drop.") # noqa: T201
1110
sys.exit()
1211

1312
api_endpoint = os.environ["ASTRA_DB_API_ENDPOINT"]
1413

15-
admin = AstraDBDatabaseAdmin(api_endpoint=api_endpoint, token=token)
14+
my_client = DataAPIClient(token=token)
15+
admin = my_client.get_admin().get_database_admin(api_endpoint)
1616
keyspaces = admin.list_keyspaces()
1717
if keyspace in keyspaces:
1818
print(f"Dropping keyspace '{keyspace}'") # noqa: T201

uv.lock

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)