Why can't I pass 'res' to embedding_array and perform vector search? Also, please help me find out where else I might be going wrong
Labels: name: area: embeddings, 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 = "lyric"
embeddings = HuggingFaceEmbeddings(
    model_name="all-MiniLM-L6-v2"
)

print("已成功連線到Qdrant")


def connection():
    client = QdrantClient(host="192.168.0.28", port=6333)

    client.recreate_collection(
        collection_name=COLLECTION_NAME,
        vectors_config=models.VectorParams(
            distance=models.Distance.COSINE,
            size=1536),
        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(
            "you are robot."
        ),
        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 main():
    qclient = connection()
    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
    data_objs = [
        {
            "id": 1,
            "lyric": f"{res}"
        },

    ]
    embedding_array = [res(text["lyric"], embeddings)
                       for text in data_objs]
    upsert_vector(qclient, embedding_array, data_objs)
    query_text = "Please repeat what I just said"
    query_embedding = res(query_text, embeddings)
    results = search_from_qdrant(qclient, query_embedding, k=1)
    print(f"select {query_text}:", results)


if __name__ == '__main__':
    main()
Why can't I pass 'res' to embedding_array and perform vector search? Also, please help me find out where else I might be going wrong
![image](https://github.com/langchain-ai/langchain/assets/103471919/22136804-e82e-4f14-9858-bc0d6da7caae)


### Suggestion:

_No response_