Find answers from the community

Updated 6 months ago

Context

At a glance

The community member is having an issue with the context_str variable in their project. They have metadata with filename and page information, and when they send a query, the prompt injects the context_str in a specific format. However, the community member finds that the language model sometimes gets confused and doesn't answer correctly. They mention that if they send the context as a JSON-formatted string, it always works.

In the comments, another community member suggests that the community member can customize how each document/node looks when it is converted to text, and they can also customize which metadata is used for embeddings and the language model. They provide a link to a guide that may help with this.

Another community member also mentions that they have a video on this topic, which the original community member says is exactly what they need.

Useful resources
Hi everybody,
First congrats, this is a fantastic project.

How can I customize the context_str variable?

My docs have a metadata with filename and page, when I send a query, the prompt
injects the context_str as

filename: contract2.txt\npage_number: 2\n\n< text >\n
filename: contract3.txt\npage_number: 3\n\n< text >\n

The problem is that the LLM sometimes get confused and don't answer correct, if I send the context as a string formatted as JSON it always works

{ context: [
{ content: "<text>", filename:"contract2.txt", page_number: 1 },
{ content: "<text>", filename:"contract3.txt", page_number: 3 }
]
}

Thanks for any help
L
B
3 comments
You can customize what each document/node looks like when it converts to text. You can even customize which metatdata is used for emebeddings and the llm

Check out the full guide here, it may help!

https://gpt-index.readthedocs.io/en/latest/core_modules/data_modules/documents_and_nodes/usage_documents.html
I also have a video on this here
https://youtu.be/nGNoacku0YY
Thanks @Logan M thats exactly what I need
Add a reply
Sign up and join the conversation on Discord