Home / Function/ aconstruct_instance() — langchain Function Reference

aconstruct_instance() — langchain Function Reference

Architecture documentation for the aconstruct_instance() function in vectorstores.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ac7b5827_8ed2_b07c_6d88_57b31096cc99["aconstruct_instance()"]
  bf62db79_4217_463c_798f_6f8528ed0d6e["Qdrant"]
  ac7b5827_8ed2_b07c_6d88_57b31096cc99 -->|defined in| bf62db79_4217_463c_798f_6f8528ed0d6e
  abe1bf7a_a00e_6397_9fc7_cf87714d9167["afrom_texts()"]
  abe1bf7a_a00e_6397_9fc7_cf87714d9167 -->|calls| ac7b5827_8ed2_b07c_6d88_57b31096cc99
  7ca49eb4_bf83_6d06_fdce_2ebfe3088d38["_generate_clients()"]
  ac7b5827_8ed2_b07c_6d88_57b31096cc99 -->|calls| 7ca49eb4_bf83_6d06_fdce_2ebfe3088d38
  style ac7b5827_8ed2_b07c_6d88_57b31096cc99 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 1779–1943

    async def aconstruct_instance(
        cls: type[Qdrant],
        texts: list[str],
        embedding: Embeddings,
        location: str | None = None,
        url: str | None = None,
        port: int | None = 6333,
        grpc_port: int = 6334,
        prefer_grpc: bool = False,  # noqa: FBT001, FBT002
        https: bool | None = None,  # noqa: FBT001
        api_key: str | None = None,
        prefix: str | None = None,
        timeout: int | None = None,
        host: str | None = None,
        path: str | None = None,
        collection_name: str | None = None,
        distance_func: str = "Cosine",
        content_payload_key: str = CONTENT_KEY,
        metadata_payload_key: str = METADATA_KEY,
        vector_name: str | None = VECTOR_NAME,
        shard_number: int | None = None,
        replication_factor: int | None = None,
        write_consistency_factor: int | None = None,
        on_disk_payload: bool | None = None,  # noqa: FBT001
        hnsw_config: models.HnswConfigDiff | None = None,
        optimizers_config: models.OptimizersConfigDiff | None = None,
        wal_config: models.WalConfigDiff | None = None,
        quantization_config: models.QuantizationConfig | None = None,
        init_from: models.InitFrom | None = None,
        on_disk: bool | None = None,  # noqa: FBT001
        force_recreate: bool = False,  # noqa: FBT001, FBT002
        **kwargs: Any,
    ) -> Qdrant:
        # Just do a single quick embedding to get vector size
        partial_embeddings = await embedding.aembed_documents(texts[:1])
        vector_size = len(partial_embeddings[0])
        collection_name = collection_name or uuid.uuid4().hex
        distance_func = distance_func.upper()
        client, async_client = cls._generate_clients(
            location=location,
            url=url,
            port=port,
            grpc_port=grpc_port,
            prefer_grpc=prefer_grpc,
            https=https,
            api_key=api_key,
            prefix=prefix,
            timeout=timeout,
            host=host,
            path=path,
            **kwargs,
        )

        collection_exists = client.collection_exists(collection_name)

        if collection_exists and force_recreate:
            client.delete_collection(collection_name)
            collection_exists = False

        if collection_exists:
            # Get the vector configuration of the existing collection and vector, if it
            # was specified. If the old configuration does not match the current one,
            # an exception is raised.
            collection_info = client.get_collection(collection_name=collection_name)
            current_vector_config = collection_info.config.params.vectors
            if isinstance(current_vector_config, dict) and vector_name is not None:
                if vector_name not in current_vector_config:
                    msg = (
                        f"Existing Qdrant collection {collection_name} does not "
                        f"contain vector named {vector_name}. Did you mean one of the "
                        f"existing vectors: {', '.join(current_vector_config.keys())}? "
                        f"If you want to recreate the collection, set `force_recreate` "
                        f"parameter to `True`."
                    )
                    raise QdrantException(msg)
                current_vector_config = current_vector_config.get(vector_name)  # type: ignore[assignment]
            elif isinstance(current_vector_config, dict) and vector_name is None:
                msg = (
                    f"Existing Qdrant collection {collection_name} uses named vectors. "
                    f"If you want to reuse it, please set `vector_name` to any of the "
                    f"existing named vectors: "

Subdomains

Called By

Frequently Asked Questions

What does aconstruct_instance() do?
aconstruct_instance() is a function in the langchain codebase, defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py.
Where is aconstruct_instance() defined?
aconstruct_instance() is defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py at line 1779.
What does aconstruct_instance() call?
aconstruct_instance() calls 1 function(s): _generate_clients.
What calls aconstruct_instance()?
aconstruct_instance() is called by 1 function(s): afrom_texts.

Analyze Your Own Codebase

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

Try Supermodel Free