Back to Llama Index

Hologres

docs/examples/vector_stores/HologresDemo.ipynb

0.14.212.9 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/vector_stores/AnalyticDBDemo.ipynb" target="_parent"></a>

Hologres

Hologres is a one-stop real-time data warehouse, which can support high performance OLAP analysis and high QPS online services.

To run this notebook you need a Hologres instance running in the cloud. You can get one following this link.

After creating the instance, you should be able to figure out following configurations with Hologres console

python
test_hologres_config = {
    "host": "<host>",
    "port": 80,
    "user": "<user>",
    "password": "<password>",
    "database": "<database>",
    "table_name": "<table_name>",
}

By the way, you need to ensure you have llama-index installed:

python
%pip install llama-index-vector-stores-hologres
python
!pip install llama-index

Import needed package dependencies:

python
from llama_index.core import (
    VectorStoreIndex,
    SimpleDirectoryReader,
    StorageContext,
)
from llama_index.vector_stores.hologres import HologresVectorStore

Load some example data:

python
!mkdir -p 'data/paul_graham/'
!curl 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -o 'data/paul_graham/paul_graham_essay.txt'

Read the data:

python
# load documents
documents = SimpleDirectoryReader("./data/paul_graham/").load_data()
print(f"Total documents: {len(documents)}")
print(f"First document, id: {documents[0].doc_id}")
print(f"First document, hash: {documents[0].hash}")
print(
    "First document, text"
    f" ({len(documents[0].text)} characters):\n{'='*20}\n{documents[0].text[:360]} ..."
)

Create the AnalyticDB Vector Store object:

python
hologres_store = HologresVectorStore.from_param(
    host=test_hologres_config["host"],
    port=test_hologres_config["port"],
    user=test_hologres_config["user"],
    password=test_hologres_config["password"],
    database=test_hologres_config["database"],
    table_name=test_hologres_config["table_name"],
    embedding_dimension=1536,
    pre_delete_table=True,
)

Build the Index from the Documents:

python
storage_context = StorageContext.from_defaults(vector_store=hologres_store)

index = VectorStoreIndex.from_documents(
    documents, storage_context=storage_context
)

Query using the index:

python
query_engine = index.as_query_engine()
response = query_engine.query("Why did the author choose to work on AI?")

print(response.response)