Document.metadata_seperator
, Document.metadata_template
, and Document.text_template
. Source ()Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:response_mode
parameter in the as_query_engine
method. Setting response_mode
to "tree_summarize"
will provide more detailed outputs, including the source nodes that contributed to the response.# set Logging to DEBUG for more detailed outputs query_engine = index.as_query_engine(response_mode="tree_summarize") response = query_engine.query("What did the author do growing up?")
display(Markdown(f"<b>{response}</b>"))
print(response.source_nodes[0].source_text)
query_modes = [ "svm", "linear_regression", "logistic_regression", ] for query_mode in query_modes: # set Logging to DEBUG for more detailed outputs query_engine = index.as_query_engine(vector_store_query_mode=query_mode) response = query_engine.query("What did the author do growing up?") print(f"Query mode: {query_mode}") display(Markdown(f"<b>{response}</b>"))
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:from llama_index.schema import TextNode, NodeRelationship, RelatedNodeInfo node1 = TextNode(text="<text_chunk>", id_="<node_id>") node2 = TextNode(text="<text_chunk>", id_="<node_id>") # set relationships node1.relationships[NodeRelationship.NEXT] = RelatedNodeInfo(node_id=node2.node_id) node2.relationships[NodeRelationship.PREVIOUS] = RelatedNodeInfo(node_id=node1.node_id) nodes = [node1, node2]
RelatedNodeInfo
class can also store additional metadata
if needed:node2.relationships[NodeRelationship.PARENT] = RelatedNodeInfo(node_id=node1.node_id, metadata={"key": "val"})
metadata
dictionary of each document will show up in the metadata
of each source node created from the document. Here's an example of how to do this:document = Document( text='text', metadata={ 'filename': '<doc_file_name>', 'category': '<category>' } )
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:relationships
attribute of the Document
and Node
objects in LlamaIndex. This attribute is a dictionary that contains relationships to other Documents/Nodes.from llama_index.schema import TextNode, NodeRelationship, RelatedNodeInfo node1 = TextNode(text="<text_chunk>", id_="<node_id>") node2 = TextNode(text="<text_chunk>", id_="<node_id>") # set relationships node1.relationships[NodeRelationship.NEXT] = RelatedNodeInfo(node_id=node2.node_id) node2.relationships[NodeRelationship.PREVIOUS] = RelatedNodeInfo(node_id=node1.node_id) nodes = [node1, node2]
node1
is set to be the next node of node2
, and node2
is set to be the previous node of node1
. This kind of relationship setting can be used to represent links between wiki documents.RelatedNodeInfo
class if needed:node2.relationships[NodeRelationship.PARENT] = RelatedNodeInfo(node_id=node1.node_id, metadata={"key": "val"})
node2
is set to be the child of node1
, and additional metadata is stored in the relationship.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:dir()
function or vars()
function. Here's how you can do it:from llama_index import Document # Create a document document = Document(text="This is a document") # Get all properties properties = dir(document) # Print all properties for property in properties: print(property)
vars()
function:# Get instance variables variables = vars(document) # Print instance variables for variable in variables: print(variable)
metadata
attribute of the Document object, which is a dictionary that contains the metadata you've set.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon: