Hmm, yea I would not use a list index for this. A list index will read every piece of data in the index, which is maybe not what you wanted.
Here's how I would re-write this approach
from llama_index import VectorStoreIndex, ServiceContext, Document
from llama_index.llms import OpenAI
# define LLM
llm = OpenAI(temperature=0.0, model="gpt-3.5-turbo", max_tokens=500)
service_context = ServiceContext.from_defaults(llm=llm, chunk_size=1024)
# Open the JSON file
with open('./data/blends.json', 'r', encoding='utf-8') as f:
data = json.load(f)
documents = []
# Iterate over products
for product in data['products']:
product_name = product['product_name']
ingredients = ', '.join(product['ingredients'])
purpose = ', '.join(product['purpose'])
document_text = (
f"Product Name: {product_name}\n"
f"Ingredients: {ingredients}\n"
f"Purpose: {purpose}\n\n"
)
document = Document(
text=document_text
)
documents.append(document)
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
query_engine = index.as_query_engine(
similarity_top_k=10. # since the documents are quite short, we can increase this from the default of 2
)
response = query_engine.query("I need something for anti inflammation")
print(response)