----------------------
In LlamaIndex, a
Vector Index
and an
Object Index
serve different purposes and are used in different contexts.
A
Vector Index
is a type of index used in LlamaIndex. It is used to index nodes based on their vector representations. This type of index is particularly useful when you want to perform similarity searches or nearest neighbor queries. Here is an example of how to construct a
Vector Index
:
from llama_index.core import VectorStoreIndex
# construct top-level vector index + query engine
vector_index = VectorStoreIndex(nodes=nodes_2021, objects=objects_2021)
query_engine = vector_index.as_query_engine(similarity_top_k=5, verbose=True)
(Source:
LlamaIndex > En > Latest > Examples > Multi_modal > LlaVa Demo with LlamaIndex¶ > Setup Composable Retriever¶ ())
On the other hand, an
Object Index
is a construct in LlamaIndex that allows the user to use index data structures over arbitrary Python objects. The
ObjectIndex
will handle serialization to/from the object, and use an underlying index (e.g.
VectorStoreIndex
,
SummaryIndex
,
KeywordTableIndex
) as the storage mechanism. Here is an example of how to construct an
Object Index
:
from llama_index.core import VectorStoreIndex
from llama_index.core.objects import ObjectIndex, SimpleToolNodeMapping
tool_mapping = SimpleToolNodeMapping.from_objects(all_tools)
obj_index = ObjectIndex.from_objects(
all_tools,
tool_mapping,
VectorStoreIndex,
)
(Source:
LlamaIndex > En > Latest > Examples > Agent > Retrieval-Augmented OpenAI Agent¶ > Building an Object Index¶ ())