-
Here is my example: from qdrant_client.models import Distance, VectorParams
from qdrant_client import QdrantClient
# Initialize the client
client = QdrantClient(":memory:")
client.create_collection(
collection_name="test_collection",
vectors_config=VectorParams(size=384, distance=Distance.COSINE),
)
# Prepare your documents, metadata, and IDs
docs = [
"Qdrant has Langchain integrations",
"Qdrant also has Llama Index integrations",
] * 5
metadata = [
{"source": "Langchain-docs"},
{"source": "Linkedin-docs"},
] * 5
client.add(collection_name="test_collection", documents=docs, metadata=metadata) If I try to Traceback (most recent call last):
File "/Users/lev/Developer/poetry-demo/poetry_demo/qdrant.py", line 40, in <module>
client.add(collection_name="test_collection", documents=docs, metadata=metadata)
File "/Users/lev/.pyenv/versions/3.11.1/envs/testing-venv/lib/python3.11/site-packages/qdrant_client/qdrant_fastembed.py", line 496, in add
self._validate_collection_info(collection_info)
File "/Users/lev/.pyenv/versions/3.11.1/envs/testing-venv/lib/python3.11/site-packages/qdrant_client/qdrant_fastembed.py", line 348, in _validate_collection_info
assert isinstance(
AssertionError: Collection have incompatible vector params: size=384 distance=<Distance.COSINE: 'Cosine'> hnsw_config=None quantization_config=None on_disk=None This is an issue because if I want to use the search_result = client.search(
collection_name="demo_collection", query_vector=[0.1, 0.2, 0.3, 0.4]
) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hello @bnkc With pure qdrant-client API (without fastembed mixin's methods like However, fastembed creates named vectors and operates with them. Names of the vectors are generated from the chosen model names. models.NamedVector(
name=client.get_vector_field_name(), vector=query_vector
) If collection was not created, then the first call to |
Beta Was this translation helpful? Give feedback.
-
Hi @joein Thanks! This worked for me :) |
Beta Was this translation helpful? Give feedback.
-
I've spent a few hours trying to figure out how to get the add and query methods working. The example code I've found for these methods doesn't really seem to work in my case, except the most trivial in memory case with only three text docs in a string, and they don't seem to be officially documented. My code is the same as above except without the config and I'm getting the same error. I don't understand how to get this answer to work in my use case, which is similar to the original poster's. If I need to learn how the underlying methods work in detail (eg what is a named vs unnamed vector), it might be helpful to update some of the public documentation since these are supposed to be "high level" methods. For instance in this answer, I don't know where If anyone has some more info I'd appreciate it while I dig through the docs. |
Beta Was this translation helpful? Give feedback.
Hello @bnkc
With pure qdrant-client API (without fastembed mixin's methods like
add
andquery
), you can have unnamed vectors, which means that you don't need to provide a name.However, fastembed creates named vectors and operates with them. Names of the vectors are generated from the chosen model names.
Thus, to do
search
, you need to setquery_vector
to a some named vector, e.g.:If collection was not created, then the first call to
add
creates it.If you want to create it on your own, take a look at
get_fastembed_vector_params
method