mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
480626dc99
…tch]: import models from community ran ```bash git grep -l 'from langchain\.chat_models' | xargs -L 1 sed -i '' "s/from\ langchain\.chat_models/from\ langchain_community.chat_models/g" git grep -l 'from langchain\.llms' | xargs -L 1 sed -i '' "s/from\ langchain\.llms/from\ langchain_community.llms/g" git grep -l 'from langchain\.embeddings' | xargs -L 1 sed -i '' "s/from\ langchain\.embeddings/from\ langchain_community.embeddings/g" git checkout master libs/langchain/tests/unit_tests/llms git checkout master libs/langchain/tests/unit_tests/chat_models git checkout master libs/langchain/tests/unit_tests/embeddings/test_imports.py make format cd libs/langchain; make format cd ../experimental; make format cd ../core; make format ```
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import logging
|
|
from pathlib import Path
|
|
|
|
from langchain.retrievers.multi_vector import MultiVectorRetriever
|
|
from langchain.storage import LocalFileStore
|
|
from langchain_community.embeddings import OpenAIEmbeddings
|
|
from langchain_community.vectorstores import Chroma
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_multi_vector_retriever(docstore_id_key: str):
|
|
"""Create the composed retriever object."""
|
|
vectorstore = get_vectorstore()
|
|
store = get_docstore()
|
|
return MultiVectorRetriever(
|
|
vectorstore=vectorstore,
|
|
byte_store=store,
|
|
id_key=docstore_id_key,
|
|
)
|
|
|
|
|
|
def get_vectorstore(collection_name: str = "proposals"):
|
|
"""Get the vectorstore used for this example."""
|
|
return Chroma(
|
|
collection_name=collection_name,
|
|
persist_directory=str(Path(__file__).parent.parent / "chroma_db_proposals"),
|
|
embedding_function=OpenAIEmbeddings(),
|
|
)
|
|
|
|
|
|
def get_docstore():
|
|
"""Get the metadata store used for this example."""
|
|
return LocalFileStore(
|
|
str(Path(__file__).parent.parent / "multi_vector_retriever_metadata")
|
|
)
|