Я использую точные модели с Langchain и работают правильно (давая мне результат). < /p>
Вот мой код Langchain: < /p> < Br />
Код: Выделить всё
from langchain_ollama import OllamaEmbeddings
from langchain_community.llms import Ollama
from langchain.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationalRetrievalChain
model = Ollama(model = 'gemma', temperature = 0.1)
embedding = OllamaEmbeddings(model = 'nomic-embed-text')
raw_documents = PyPDFLoader(path+file).load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1500, chunk_overlap=200)
documents = text_splitter.split_documents(raw_documents)
db = FAISS.from_documents(documents, embedding)
memory = ConversationBufferMemory(memory_key='chat_history', return_messages = True)
query_engine = ConversationalRetrievalChain.from_llm(model, retriever=db.as_retriever(), memory=memory, verbose=True)
response = query_engine.run({'question':'when in the registration period'})
print(response)
# The registration period is between Jan to Feb.
и Это для llamaindex: < /p>
from llama_index.llms.ollama import Ollama
from llama_index.embeddings.ollama import OllamaEmbedding
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
from llama_index.core.ingestion import IngestionPipeline
from llama_index.core.node_parser import TokenTextSplitter
Settings.llm = Ollama(model="gemma", request_timeout=360.0)
Settings.embed_model = OllamaEmbedding(model_name="nomic-embed-text")
documents = SimpleDirectoryReader(path).load_data(file)
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("when in the registration period")
print(response)
# The provided text does not contain information regarding..., so I am unable to answer this query from the given context.
< /code>
Тем не менее, этот LmamainDex вызывает, что он не может найти информацию в предоставленном документе. >
I expcet, результаты, которые являются simialr, поскольку я использую аналогичную модель встраивания и чата.
Подробнее здесь: https://stackoverflow.com/questions/793 ... tion-regar