Why can't you search vectors?
Labels: name: area: vector store, name: auto:bug

### Issue you'd like to raise.

from langchain.chains import ConversationalRetrievalChain, ConversationChain, LLMChain
from langchain.memory import ConversationTokenBufferMemory
from langchain_community.chat_models import ChatOpenAI
from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain_core.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, MessagesPlaceholder, \
    HumanMessagePromptTemplate
from qdrant_client import QdrantClient, models
import os
from qdrant_client.grpc import PointStruct

os.environ['OPENAI_API_KEY'] = "mykey"
COLLECTION_NAME = "teeeeee"
embeddings = HuggingFaceEmbeddings(
    model_name="all-MiniLM-L6-v2"
)

print("已成功連線到Qdrant")


def connection():
    client = QdrantClient(host="192.168.0.311", port=6333)

    client.recreate_collection(
        collection_name=COLLECTION_NAME,
        vectors_config=models.VectorParams(
            distance=models.Distance.COSINE,
            size=384),
        optimizers_config=models.OptimizersConfigDiff(memmap_threshold=20000),
        hnsw_config=models.HnswConfigDiff(on_disk=True, m=16, ef_construct=100)
    )
    return client


prompt = ChatPromptTemplate(
    messages=[
        SystemMessagePromptTemplate.from_template(
            "你是耶米菈."
        ),
        MessagesPlaceholder(variable_name="chat_history"),
        HumanMessagePromptTemplate.from_template("{question}"),
    ]
)
llm_name = "gpt-3.5-turbo"
llm = ChatOpenAI(model_name=llm_name, temperature=0)
memory_token_limit = 2000

memory = ConversationTokenBufferMemory(
    llm=llm,
    prompt=prompt,
    max_token_limit=int(memory_token_limit),
    memory_key="chat_history",
    return_messages=True,
)

conversation = LLMChain(llm=llm, prompt=prompt, verbose=True, memory=memory)
chat_history = []


def upsert_vector(client, vectors, data):
    for i, vector in enumerate(vectors):
        client.upsert(
            collection_name=COLLECTION_NAME,
            points=[PointStruct(id=i,
                                vector=vectors[i],
                                payload=data[i])]
        )

    print("upsert finish")


def search_from_qdrant(client, vector, k=1):
    search_result = client.search(
        collection_name=COLLECTION_NAME,
        query_vector=vector,
        limit=k,
        append_payload=True,
    )
    return search_result


def get_embedding(text, model_name):
    while True:
        memory.load_memory_variables({})
        question = input('提問：')
        result = conversation.run({'question': question, 'chat_history': chat_history})
        print(result)
        chat_history.append([f'User: {question}', f'Ai: {result}'])
        print(chat_history)
        st_history = ' '.join(map(str, chat_history))
        res = embeddings.embed_query(st_history)

        print(f'ok: {res[:4]}...')
        if question.lower() == 'bye':
            break
    return st_history


def main():
    qclient = connection()
    data_objs = [
        {
            "id": 1,
            "teeeeee": f"我是阿狗。你叫做阿狗"
        },

    ]
    embedding_array = [get_embedding(text["teeeeee"], embeddings)
                       for text in data_objs]
    upsert_vector(qclient, embedding_array, data_objs)
    query_text = "請複誦我剛才所說的話"
    query_embedding = get_embedding(query_text, embeddings)
    results = search_from_qdrant(qclient, query_embedding, k=1)
    print(f"尋找 {query_text}:", results)


if __name__ == '__main__':
    main()


Execution result:

Traceback (most recent call last):
  File "C:\Users\syz\Downloads\Chat-Bot-using-gpt-3.5-turbo-main\models\測.py", line 117, in <module>
    main()
  File "C:\Users\syz\Downloads\Chat-Bot-using-gpt-3.5-turbo-main\models\測.py", line 109, in main
    upsert_vector(qclient, embedding_array, data_objs)
  File "C:\Users\syz\Downloads\Chat-Bot-using-gpt-3.5-turbo-main\models\測.py", line 63, in upsert_vector
    points=[PointStruct(id=i,
            ^^^^^^^^^^^^^^^^^
TypeError: Message must be initialized with a dict: qdrant.PointStruct

### Suggestion:

_No response_