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_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.1.0.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.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_vector_stores_db2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 64a5c5300dd0cbc9110cb50d9c5d048758aeb44d856602d979fb18e66ce1a15c
MD5 a25ff45973fbfda2fab5bca8fb59da08
BLAKE2b-256 b4893a14a02b0f37d384a84d6e96f10c2eeb7836b83f7aa5b924c6b0b60e97a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_vector_stores_db2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9dffc65fc31c28de489b6ad9181a2bf62e8f0b77ab005e12ae58ef80c0c0690
MD5 25f87e5ef70709958df7237f5e0ea8f8
BLAKE2b-256 12d1d650c959629a805536f220aa8ac4b4664fa4e9de154bf588675ec962eabb

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