Reputation: 53
I'm working on a function that processes a list of multiple-choice questions using various machine learning models and stores the results in a vector space. The function, let's call it process_questions, takes a list of question objects and performs the following steps:
Initialize Embeddings Model: It begins by loading an embeddings model, which is used to represent the questions and possible answers in a high-dimensional space.
Setup Vector Store with Redis: Then, it sets up a vector store using Redis, where the embeddings are stored. The setup includes specifying the dimensions (e.g., "1000x200") and chunking parameters for efficient storage and retrieval.
Create and Bind a Processing Chain: The function then initializes a processing chain, which is responsible for evaluating the questions. This chain uses a retriever from the vector store to find relevant information and compute the best answers.
Iterate Over Questions: The function iterates through the provided questions. During each iteration, it processes the question using the chain, records the processing steps, and prints the question's correct answer and the computed response.
Record and Output Results: For each question, the function records the processing details in a structured format (like JSON) and prints this information along with the question's correct answer and the system's response.
I'm trying to understand the error that is happening when i pass my chain to the TruChain class. My error says
self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for TruChain
records_with_pending_feedback_results
Input should be an instance of Queue [type=is_instance_of, input_value=<queue.Queue object at 0x124dd68b0>, input_type=Queue]
For further information visit https://errors.pydantic.dev/2.6/v/is_instance_of
I am not sure if this is something I can fix or how to circumvent this. Please any advice would be appreciated!
main.py
python
from trulens_eval.feedback import Feedback, Groundedness
from trulens_eval import OpenAI as fOpenAI
from trulens_eval import TruChain
from trulens_eval.app import App
from typing import List
def process_questions(questions: List[QuestionType]):
# Load the base embeddings model; specifics are abstracted
embeddings = load_embeddings_model()
# Initialize the vector store with the embeddings model
vector_store = VectorStore(embeddings, "dimension_spec", chunk_size=1000, chunk_overlap=200)
# Initialize the processing mechanism with the vector store's retriever
processing_mechanism = ProcessingMechanism(vector_store.get_retriever())
print("Processing Mechanism Type: ", type(processing_mechanism))
# Construct and configure the processing chain
processing_chain = processing_mechanism.construct_chain()
processing_chain.bind(tags="ConfigurationTags")
tru_recorder = TruChain(chain) ## This is where my error occurs, I am attempting to follow the TruChain documentation but for some reason this line still invokes an error
# Iterate through the questions, process them, and handle responses
for question in questions:
print(counter)
counter += 1
# Invoke the processing chain on the question data and record the process
response, record = recorder.with_record(processing_chain.invoke, question.to_dict())
print(f"Correct answer: {question.answer}")
print('Response: ', response)
# Output the recorded process in a structured format
json_like = record.layout_as_app()
print("Record Output: ", json_like)
Upvotes: 0
Views: 49
Reputation: 53
After trashing my entire virtual environment and starting a new one with conda instead of pipenv it was able to work. Not 100% why. If anyone runs into the same issue I would recommend just starting a new environment. I used Python 3.10.14
Upvotes: 0