Home / File/ test_add_texts.py — langchain Source File

test_add_texts.py — langchain Source File

Architecture documentation for test_add_texts.py, a python file in the langchain codebase. 8 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  bfee95ec_6240_a2ab_2054_fb9486ade0a5["test_add_texts.py"]
  9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  77801658_6b3a_bc26_7e54_388e5c04807d["langchain_qdrant"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> 77801658_6b3a_bc26_7e54_388e5c04807d
  a50ef027_f19e_86a8_94ef_895b4566f94e["tests.integration_tests.common"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> a50ef027_f19e_86a8_94ef_895b4566f94e
  513f2bf4_0acd_14e4_0a43_45f7716ce101["tests.integration_tests.fixtures"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> 513f2bf4_0acd_14e4_0a43_45f7716ce101
  e9f800f2_8227_1095_42ef_324e02810451["qdrant_client"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> e9f800f2_8227_1095_42ef_324e02810451
  da77c41d_c17b_8187_a5db_d7d2c445d3ab["qdrant_client.http"]
  bfee95ec_6240_a2ab_2054_fb9486ade0a5 --> da77c41d_c17b_8187_a5db_d7d2c445d3ab
  style bfee95ec_6240_a2ab_2054_fb9486ade0a5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import os
import uuid

import pytest  # type: ignore[import-not-found]

from langchain_qdrant import Qdrant
from tests.integration_tests.common import ConsistentFakeEmbeddings
from tests.integration_tests.fixtures import qdrant_locations

API_KEY = os.getenv("QDRANT_API_KEY")


@pytest.mark.parametrize("batch_size", [1, 64])
@pytest.mark.parametrize("qdrant_location", qdrant_locations())
async def test_qdrant_aadd_texts_returns_all_ids(
    batch_size: int, qdrant_location: str
) -> None:
    """Test end to end Qdrant.aadd_texts returns unique ids."""
    docsearch: Qdrant = Qdrant.from_texts(
        ["foobar"],
        ConsistentFakeEmbeddings(),
        batch_size=batch_size,
        location=qdrant_location,
    )

    ids = await docsearch.aadd_texts(["foo", "bar", "baz"])
    assert len(ids) == 3
    assert len(set(ids)) == 3


@pytest.mark.parametrize("vector_name", [None, "my-vector"])
@pytest.mark.parametrize("qdrant_location", qdrant_locations())
async def test_qdrant_aadd_texts_stores_duplicated_texts(
    vector_name: str | None, qdrant_location: str
) -> None:
    """Test end to end Qdrant.aadd_texts stores duplicated texts separately."""
    from qdrant_client import QdrantClient
    from qdrant_client.http import models as rest

    client = QdrantClient(location=qdrant_location, api_key=API_KEY)
    collection_name = uuid.uuid4().hex
    vectors_config = rest.VectorParams(size=10, distance=rest.Distance.COSINE)
    if vector_name is not None:
        vectors_config = {vector_name: vectors_config}  # type: ignore[assignment]
    client.recreate_collection(collection_name, vectors_config=vectors_config)

    vec_store = Qdrant(
        client,
        collection_name,
        embeddings=ConsistentFakeEmbeddings(),
        vector_name=vector_name,
    )
    ids = await vec_store.aadd_texts(["abc", "abc"], [{"a": 1}, {"a": 2}])

    assert len(set(ids)) == 2
    assert client.count(collection_name).count == 2


// ... (67 more lines)

Subdomains

Dependencies

  • langchain_qdrant
  • os
  • pytest
  • qdrant_client
  • qdrant_client.http
  • tests.integration_tests.common
  • tests.integration_tests.fixtures
  • uuid

Frequently Asked Questions

What does test_add_texts.py do?
test_add_texts.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_add_texts.py?
test_add_texts.py defines 4 function(s): test_qdrant_aadd_texts_returns_all_ids, test_qdrant_aadd_texts_stores_duplicated_texts, test_qdrant_aadd_texts_stores_embeddings_as_named_vectors, test_qdrant_aadd_texts_stores_ids.
What does test_add_texts.py depend on?
test_add_texts.py imports 8 module(s): langchain_qdrant, os, pytest, qdrant_client, qdrant_client.http, tests.integration_tests.common, tests.integration_tests.fixtures, uuid.
Where is test_add_texts.py in the architecture?
test_add_texts.py is located at libs/partners/qdrant/tests/integration_tests/async_api/test_add_texts.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/partners/qdrant/tests/integration_tests/async_api).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free