construct_instance() — langchain Function Reference
Architecture documentation for the construct_instance() function in vectorstores.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 235bfe39_60a0_33c8_29fd_c522181e5cd2["construct_instance()"] 2d095452_70a7_4606_a1b1_4650d16b5343["Qdrant"] 235bfe39_60a0_33c8_29fd_c522181e5cd2 -->|defined in| 2d095452_70a7_4606_a1b1_4650d16b5343 28bc0529_3070_278b_cfbe_477195e650e6["from_texts()"] 28bc0529_3070_278b_cfbe_477195e650e6 -->|calls| 235bfe39_60a0_33c8_29fd_c522181e5cd2 70d729b6_ce69_8de2_eb3a_2d1064ecffac["_generate_clients()"] 235bfe39_60a0_33c8_29fd_c522181e5cd2 -->|calls| 70d729b6_ce69_8de2_eb3a_2d1064ecffac style 235bfe39_60a0_33c8_29fd_c522181e5cd2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 1614–1776
def construct_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 = embedding.embed_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: "
f"{', '.join(current_vector_config.keys())}."
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does construct_instance() do?
construct_instance() is a function in the langchain codebase, defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py.
Where is construct_instance() defined?
construct_instance() is defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py at line 1614.
What does construct_instance() call?
construct_instance() calls 1 function(s): _generate_clients.
What calls construct_instance()?
construct_instance() is called by 1 function(s): from_texts.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free