Skip to main content

llama-index vector_stores db2 database integration

Project description

LlamaIndex VectorStore Integration for IBM Db2

For a detailed guide look at https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/vector_stores/db2llamavs.ipynb

pip install llama-index-vector-stores-db2

A sample example

from typing import TYPE_CHECKING
import sys
from llama_index.core.schema import Document, TextNode
from llama_index.vector_stores.db2 import DB2LlamaVS, DistanceStrategy
from llama_index.vector_stores.db2 import base as db2llamavs

if TYPE_CHECKING:
    import ibm_db

"""
Create connection to Db2 database instance

The following sample code will show how to connect to Db2 Database. Besides the dependencies above, you will need a Db2 database instance (with version v12.1.2+, which has the vector datatype support) running.
"""

import ibm_db
import ibm_db_dbi

database = ""
username = ""
password = ""

try:
    connection = ibm_db_dbi.connect(database, username, password)
    print("Connection successful!")
except Exception as e:
    print("Connection failed!", e)


"""
Create Db2 vector store
"""

vectorstore = DB2LlamaVS.from_documents(
    client=conn,
    docs=chunks_with_mdata,
    table_name="db2vs",
    distance_strategy=DistanceStrategy.DOT_PRODUCT,
)

"""
Perform Similarity search
"""

# Similarity search
query = VectorStoreQuery(query_embedding=[1.0, 1.0], similarity_top_k=3)
results = vectorstore.query(query=query)
print(f"\n\n\nSimilarity search results for vector store: {results}\n\n\n")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_vector_stores_db2-0.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_vector_stores_db2-0.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_vector_stores_db2-0.0.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_vector_stores_db2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 27fb30b6597be2a2e4bfba48754444608e9b1be7a480524c6b01111b12db33ce
MD5 74f9f10dd866711318b316d624718474
BLAKE2b-256 3aee660604cd4bcabcfb14a978acd3aa22bf3bb9fa64c46dc58b78eec5ec137b

See more details on using hashes here.

File details

Details for the file llama_index_vector_stores_db2-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_vector_stores_db2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 492160ea63ab4a97529c6496a0af2384ff260517fd6a7242424ec41358952d65
MD5 6ca226922c93769b366a6a134642d0d7
BLAKE2b-256 91927ca4553d16f8c7d09d77ab5e4e63dc415d41214e1338d004d3970e0d9bbb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page