Skip to content

LangChain Store

Jael Gu edited this page Jul 13, 2023 · 1 revision

VectorStore

The VectorStore module is used to store doc embeddings and enable semantic search. By default, it uses Milvus in LangChain.

If you want to configure this module in operations, refer to Configuration.

If you want to use your own method, follow steps below:

  1. Write your module and add the script file under the vector_store directory. Your module should follow API design below to adapt operations in chatbot:

    VectorStore(table_name: str, embedding_func: Embeddings)

    Parameters:

    • table_name (str): table name in vector database
    • embedding_func (Embeddings): embedding method to convert query or documents to vectors

    Methods:

    • insert: data insert, given a list of documents, returns how many data entities inserted
    • search: semantic search, given a query in string, returns a list of useful documents
  2. You need to import MemoryStore from your module file instead of default file. Just modify init.py under the store directory.

    from .vector_store.your_file import VectorStore

ScalarStore

The ScalarStore is storage of scalar data, which allows information retrieval other than semantic search, such as keyword match. By default, it uses ElasticSearch BM25 in LangChain.

If you want to configure this module in operations, refer to Configuration.

If you want to use your own method, follow steps below:

  1. Write your module and add the script file under the scalar_store directory. Your module should follow API design below to adapt operations in chatbot:

    ScalarStore(index_name: str, client: CLIENT)

    Parameters:

    • index_name (str): table name in scalar database
    • client: method to connect database

    Methods:

    • insert: data insert, given a list of documents, returns how many data entities inserted
    • search: scalar search, given a query in string, returns a list of useful documents
  2. You need to import MemoryStore from your module file instead of default file. Just modify init.py under the store directory.

    from .scalar_store.your_file import ScalarStore

MemoryStore

The MemoryStore module records chat history in database. By default, it uses PostgresChatMessageHistory and ConversationBufferMemory in LangChain to build memory.

If you want to configure this module in operations, refer to Configuration.

If you want to use your own method, follow steps below:

  1. Write your module and add the script file under the memory_store directory. Your module should follow API design below to adapt operations in chatbot:

    MemoryStore(table_name: str, session_id: str)

    Parameters:

    • table_name (str): table name in database
    • session_id (str): identifier for sessions, allowing for different sessions of conversation

    Attributes:

    • memory (BaseMemory): a LangChain base memory to adapt agent

    Methods:

    • add_history: insert chat history to database, given a list of dictionaries with keys of 'question' and 'answer', [{'question': 'xxx', 'answer': 'xxx'}]
    • get_history: return chat history in a list of tuples, [('this is question', 'this is answer')]
  2. You need to import MemoryStore from your module file instead of default file. Just modify init.py under the store directory.

    from .memory_store.your_file import MemoryStore
Clone this wiki locally