from haystack.document_stores import FAISSDocumentStore document_store = FAISSDocumentStore(faiss_index_factory_str="Flat", embedding_dim=1024)
Загрузка и обработка документов
from haystack.utils import clean_wiki_text, convert_files_to_docs doc_dir = "test" docs = convert_files_to_docs(dir_path=doc_dir, clean_func=clean_wiki_text, split_paragraphs=True) document_store.write_documents(docs)
from haystack.nodes import EmbeddingRetriever
Использование модели, поддерживающей русский язык
retriever = EmbeddingRetriever( document_store=document_store, embedding_model="AlexKay/xlm-roberta-large-qa-multilingual-finedtuned-ru" ) document_store.update_embeddings(retriever)
from haystack.nodes import FARMReader
Использование модели для русского языка
reader = FARMReader(model_name_or_path="AlexKay/xlm-roberta-large-qa-multilingual-finedtuned-ru", use_gpu=False)
from haystack.pipelines import ExtractiveQAPipeline pipe = ExtractiveQAPipeline(reader, retriever)
Запрос на русском языке
query = "директор Института электроэнергетики и электроники?" prediction = pipe.run( query=query, params={"Retriever": {"top_k": 10}, "Reader": {"top_k": 10}} ) print(prediction)