Skip to content

Commit 9ca7ab6

Browse files
authored
Enable ruff docstring-code-format (#154)
1 parent 7beef9c commit 9ca7ab6

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

libs/astradb/langchain_astradb/vectorstores.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ class AstraDBVectorStore(VectorStore):
401401
Setup:
402402
Install the ``langchain-astradb`` package and head to the
403403
`AstraDB website <https://astra.datastax.com>`_, create an account, create a
404-
new database and `create an application token <https://docs.datastax.com/en/astra-db-serverless/administration/manage-application-tokens.html>`_.
404+
new database and
405+
`create an application token <https://docs.datastax.com/en/astra-db-serverless/administration/manage-application-tokens.html>`_.
405406
406407
.. code-block:: bash
407408
@@ -424,7 +425,8 @@ class AstraDBVectorStore(VectorStore):
424425
Instantiate:
425426
Get your API endpoint and application token from the dashboard of your database.
426427
427-
Create a vector store and provide a LangChain embedding object for working with it:
428+
Create a vector store and provide a LangChain embedding object for working with
429+
it:
428430
429431
.. code-block:: python
430432
@@ -434,7 +436,9 @@ class AstraDBVectorStore(VectorStore):
434436
from langchain_openai import OpenAIEmbeddings
435437
436438
ASTRA_DB_API_ENDPOINT = getpass.getpass("ASTRA_DB_API_ENDPOINT = ")
437-
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass("ASTRA_DB_APPLICATION_TOKEN = ")
439+
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass(
440+
"ASTRA_DB_APPLICATION_TOKEN = "
441+
)
438442
439443
vector_store = AstraDBVectorStore(
440444
collection_name="astra_vector_langchain",
@@ -443,8 +447,10 @@ class AstraDBVectorStore(VectorStore):
443447
token=ASTRA_DB_APPLICATION_TOKEN,
444448
)
445449
446-
(Vectorize) Create a vector store where the embedding vector computation happens entirely
447-
on the server-side, using the `vectorize <https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html>`_ feature:
450+
(Vectorize) Create a vector store where the embedding vector computation
451+
happens entirely on the server-side, using the
452+
`vectorize <https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html>`_
453+
feature:
448454
449455
.. code-block:: python
450456
@@ -454,7 +460,9 @@ class AstraDBVectorStore(VectorStore):
454460
from langchain_astradb import AstraDBVectorStore
455461
456462
ASTRA_DB_API_ENDPOINT = getpass.getpass("ASTRA_DB_API_ENDPOINT = ")
457-
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass("ASTRA_DB_APPLICATION_TOKEN = ")
463+
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass(
464+
"ASTRA_DB_APPLICATION_TOKEN = "
465+
)
458466
459467
vector_store = AstraDBVectorStore(
460468
collection_name="astra_vectorize_langchain",
@@ -485,14 +493,18 @@ class AstraDBVectorStore(VectorStore):
485493
from langchain_astradb import AstraDBVectorStore
486494
487495
ASTRA_DB_API_ENDPOINT = getpass.getpass("ASTRA_DB_API_ENDPOINT = ")
488-
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass("ASTRA_DB_APPLICATION_TOKEN = ")
496+
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass(
497+
"ASTRA_DB_APPLICATION_TOKEN = "
498+
)
489499
490500
vector_store = AstraDBVectorStore(
491501
collection_name="astra_vectorize_langchain",
492502
# embedding=..., # needed unless using 'vectorize'
493503
api_endpoint=ASTRA_DB_API_ENDPOINT,
494504
token=ASTRA_DB_APPLICATION_TOKEN,
495-
collection_vector_service_options=VectorServiceOptions(...), # see above
505+
collection_vector_service_options=VectorServiceOptions(
506+
...
507+
), # see above
496508
collection_lexical=CollectionLexicalOptions(analyzer="standard"),
497509
collection_rerank=CollectionRerankOptions(
498510
service=RerankServiceOptions(
@@ -509,11 +521,13 @@ class AstraDBVectorStore(VectorStore):
509521
the options to resolve are:
510522
(1) use autodetect mode, (2) switch to ``setup_mode`` "OFF", or
511523
(3) explicitly specify lexical and/or rerank settings in the vector
512-
store constructor, to match the existing collection configuration.
513-
See `here <https://github.com/langchain-ai/langchain-datastax/blob/main/libs/astradb/README.md#collection-defaults-mismatch>`_ for more details.
524+
store constructor, to match the existing collection configuration. See
525+
`here <https://github.com/langchain-ai/langchain-datastax/blob/main/libs/astradb/README.md#collection-defaults-mismatch>`_
526+
for more details.
514527
515-
(Autodetect) Let the vector store figure out the configuration (including vectorize
516-
and document encoding scheme on DB), by inspection of an existing collection:
528+
(Autodetect) Let the vector store figure out the configuration (including
529+
vectorize and document encoding scheme on DB), by inspection of an existing
530+
collection:
517531
518532
.. code-block:: python
519533
@@ -522,7 +536,9 @@ class AstraDBVectorStore(VectorStore):
522536
from langchain_astradb import AstraDBVectorStore
523537
524538
ASTRA_DB_API_ENDPOINT = getpass.getpass("ASTRA_DB_API_ENDPOINT = ")
525-
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass("ASTRA_DB_APPLICATION_TOKEN = ")
539+
ASTRA_DB_APPLICATION_TOKEN = getpass.getpass(
540+
"ASTRA_DB_APPLICATION_TOKEN = "
541+
)
526542
527543
vector_store = AstraDBVectorStore(
528544
collection_name="astra_existing_collection",
@@ -575,7 +591,7 @@ class AstraDBVectorStore(VectorStore):
575591
Search:
576592
.. code-block:: python
577593
578-
results = vector_store.similarity_search(query="thud",k=1)
594+
results = vector_store.similarity_search(query="thud", k=1)
579595
for doc in results:
580596
print(f"* {doc.page_content} [{doc.metadata}]")
581597
@@ -586,7 +602,9 @@ class AstraDBVectorStore(VectorStore):
586602
Search with filter:
587603
.. code-block:: python
588604
589-
results = vector_store.similarity_search(query="thud",k=1,filter={"bar": "baz"})
605+
results = vector_store.similarity_search(
606+
query="thud", k=1, filter={"bar": "baz"}
607+
)
590608
for doc in results:
591609
print(f"* {doc.page_content} [{doc.metadata}]")
592610
@@ -597,7 +615,7 @@ class AstraDBVectorStore(VectorStore):
597615
Search with score:
598616
.. code-block:: python
599617
600-
results = vector_store.similarity_search_with_score(query="qux",k=1)
618+
results = vector_store.similarity_search_with_score(query="qux", k=1)
601619
for doc, score in results:
602620
print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
603621
@@ -615,11 +633,11 @@ class AstraDBVectorStore(VectorStore):
615633
await vector_store.adelete(ids=["3"])
616634
617635
# search
618-
results = vector_store.asimilarity_search(query="thud",k=1)
636+
results = vector_store.asimilarity_search(query="thud", k=1)
619637
620638
# search with score
621-
results = await vector_store.asimilarity_search_with_score(query="qux",k=1)
622-
for doc,score in results:
639+
results = await vector_store.asimilarity_search_with_score(query="qux", k=1)
640+
for doc, score in results:
623641
print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
624642
625643
.. code-block:: none
@@ -639,7 +657,7 @@ class AstraDBVectorStore(VectorStore):
639657
640658
[Document(metadata={'bar': 'baz'}, page_content='thud')]
641659
642-
""" # noqa: E501
660+
"""
643661

644662
def filter_to_query(self, filter_dict: dict[str, Any] | None) -> dict[str, Any]:
645663
"""Prepare a query for use on DB based on metadata filter.

libs/astradb/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ test_integration = [
4444
]
4545
codespell = ["codespell<3.0.0,>=2.2.0"]
4646

47+
[tool.ruff.format]
48+
docstring-code-format = true
49+
4750
[tool.ruff.lint]
4851
pydocstyle.convention = "google"
4952
pep8-naming.classmethod-decorators = [

0 commit comments

Comments
 (0)