Issue: <"How can I extract vector data from pgvector for use as a reference in the next conversation to enable long-term memory functionality for my chatbot?>
Labels: name: area: embeddings, name: auto:question

### Issue you'd like to raise.

from langchain.chains import LLMChain
from langchain.prompts import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    MessagesPlaceholder,
    SystemMessagePromptTemplate,
)
import psycopg2
import os
from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferMemory
from sentence_transformers import SentenceTransformer

os.environ['OPENAI_API_KEY'] = "key"
database = "MemoryChatBot"
user = "xxxxxxx"
password = "xxx"
host = "1x2.xxx.0x.xx"
port = "5432"
conn = psycopg2.connect(database=database, user=user, password=password, host=host, port=port)
print("ok!")
llm = ChatOpenAI(
    temperature=0.7,
    model="gpt-3.5-turbo",
    max_tokens=100
)
prompt = ChatPromptTemplate(
    messages=[
        SystemMessagePromptTemplate.from_template(
            "you are robot."
        ),
        MessagesPlaceholder(variable_name="chat_history"),
        HumanMessagePromptTemplate.from_template("{question}"),
    ]
)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
conversation = LLMChain(llm=llm, prompt=prompt, verbose=False, memory=memory)
all_history = []
while True:
    chat_history = memory.load_memory_variables({})
    question = input('user：')
    result = conversation.run({'question': question, 'chat_history': chat_history})
    memory.save_context({question: question}, {result: result})
    talk_all = conversation.memory.buffer
    all_history.append(talk_all)
    print(result)
    if question.lower() == 'bye':
        st_history = ' '.join(map(str, all_history))
        model = SentenceTransformer('flax-sentence-embeddings/all_datasets_v3_MiniLM-L12') #384emb
        # model = SentenceTransformer('BAAI/bge-large-zh-v1.5') #1024emb
        res = model.encode(st_history)
        model.query_instruction = "test"
        res_str = str(res.tolist())
        cursor = conn.cursor()
        sql = f"INSERT INTO tmp04 (embedding) VALUES ('{res_str}')"
        cursor.execute(sql)
        conn.commit()
        print(f'embedding:  {res[:4].tolist()}...')
        print("ok!")
        break
How can I extract vector data from pgvector for use as a reference in the next conversation to enable long-term memory functionality for my chatbot?  
![未命名](https://github.com/langchain-ai/langchain/assets/103471919/895afdca-c749-4c3a-9ec5-b0c2ee42ec23)


### Suggestion:

The usage of pgvector's Retrievers is unclear.
Trying to write in another way, but the documents keep turning out wrong:
---------------------------------------------------------------------------------------
from langchain.chains import LLMChain
from langchain.prompts import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    MessagesPlaceholder,
    SystemMessagePromptTemplate,
)
from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferMemory
from langchain_community.vectorstores.pgvector import PGVector
from langchain.vectorstores.pgvector import DistanceStrategy
from langchain_community.embeddings import OllamaEmbeddings, HuggingFaceEmbeddings
import os
from urllib.parse import quote_plus

os.environ['OPENAI_API_KEY'] = "xxxxxx"
database = "xxx"
user = "xxxxx"
password = quote_plus("x@xxx")
host = "xx.xxx.0.xx"
port = "5432"
print("ok")
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
CONNECTION_STRING = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}"
documents = []
db = PGVector.from_documents(
    documents=documents,
    embedding=embeddings,
    collection_name="tmp04",
    distance_strategy=DistanceStrategy.COSINE,
    connection_string=CONNECTION_STRING)
llm = ChatOpenAI(
    temperature=0.7,
    model="gpt-3.5-turbo",
    max_tokens=100
)
prompt = ChatPromptTemplate(
    messages=[
        SystemMessagePromptTemplate.from_template(
            "you are robot."
        ),
        MessagesPlaceholder(variable_name="chat_history"),
        HumanMessagePromptTemplate.from_template("{question}"),
    ]
)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
conversation = LLMChain(llm=llm, prompt=prompt, verbose=False, memory=memory)
while True:
    chat_history = memory.load_memory_variables({})
    question = input('ask：')
    embedding = embeddings.embed_query(question)
    documents.append(embedding)
    print(documents)
    result = conversation.run({'question': question, 'chat_history': chat_history, })
    memory.save_context({question: question}, {result: result})
    talk_all = conversation.memory.buffer
    documents.append(talk_all)
    print(result)
    if question.lower() == 'bye':
        print("ok")
        break