Skip to main content

Async + Sync Python SDK for the Vector Database API

Project description

Code Example

pip install vector_db_1807

or

uv add vector_db_1807
import os
import json
from langchain_community.document_loaders import PyPDFLoader
from langchain_ollama import OllamaEmbeddings, OllamaLLM
# import your local SDK client
from vector_db_1807 import VectorClient

# ---------------- CONFIG ----------------
API_URL = ""
API_KEY = ""
PDF_FILE = ""
TOP_K = 3

# ---------------- INIT ----------------
embedder = OllamaEmbeddings(model="llama3.2")     
llm = OllamaLLM(model="llama3.2")

# Vector DB SDK client
client = VectorClient(
    api_key=API_KEY,
    base_url=API_URL,
)

# ---------------- LOAD PDF ----------------
loader = PyPDFLoader(PDF_FILE)
pages = loader.load()
full_text = "\n\n".join([p.page_content for p in pages])

print(f"[INFO] Loaded {len(pages)} pages from {PDF_FILE}")


# ---------------- CREATE EMBEDDING ----------------
embedding = embedder.embed_query(full_text)

metadata = {
    "text": full_text,
    "file_name": os.path.basename(PDF_FILE),
    "source": "resume",
}


# ---------------- STEP 1: ADD VECTOR ----------------
print("\n[INFO] Uploading vector using VectorClient...")

add_resp = client.add_vector(
    embedding=embedding,
    metadata=metadata,
)

print("[INFO] Added successfully:\n", json.dumps(add_resp, indent=2))

document_id = add_resp["data"]["document_id"]


# ---------------- STEP 2: SEARCH ----------------
query = "What companies/organizations has he worked in so far?"
query_vector = embedder.embed_query(query)

print("\n[INFO] Searching via VectorClient...")

search_resp = client.search(
    query_vector=query_vector,
    document_id=document_id,
    top_k=TOP_K
)

results = search_resp["data"]["results"]

print("[INFO] Search results:", json.dumps(results, indent=2))

if not results:
    print("[WARN] No vector matches found.")
    exit()

best = results[0]
context = best["metadata"]["text"]

print(f"[INFO] Using context from: {best['metadata']['file_name']}")


# ---------------- STEP 3: LLM ANSWER ----------------
prompt = f"""
Answer the question ONLY using the following context:

<context>
{context}
</context>

Question: {query}

Answer:
"""

answer = llm.invoke(prompt)

print("\n" + "="*60)
print("QUESTION:", query)
print("ANSWER:\n", answer)
print("="*60)

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

vector_db_1807-0.4.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

vector_db_1807-0.4.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file vector_db_1807-0.4.2.tar.gz.

File metadata

  • Download URL: vector_db_1807-0.4.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for vector_db_1807-0.4.2.tar.gz
Algorithm Hash digest
SHA256 df2c5ea19886f4c4d421d5c19e18779827d316a5150391d26ee07039ea67ab9f
MD5 3a58d0eb1d23103e8ffbf9bab0d5e5bc
BLAKE2b-256 26eaa571b85599d9399cef17612a0567dbb60aa17cc388808bc5f6fdba81c3df

See more details on using hashes here.

File details

Details for the file vector_db_1807-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for vector_db_1807-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0a66352fea273e2ea1da1673e05d0cbfb3cbc87f3562ac4a53e072044e9cdeb
MD5 5b14e766dd35c9c59f6c0eb88abc333b
BLAKE2b-256 0bc1bc5828666053658d6f1e47faa2f1e8e1d49c04ff837346134ca2c4b8a838

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