Quick Start

This guide will help you get started with the DataBridge Python SDK by walking through the basic operations.

Connecting to DataBridge

First, import and initialize the DataBridge client:

from databridge.sync import DataBridge

# Connect to a local instance (no authentication)
db = DataBridge()

# Connect to a remote instance with authentication
db = DataBridge("databridge://owner_id:token@api.databridge.ai")

# Using a context manager (recommended)
with DataBridge() as db:
    # Your code here
    pass

Ingesting Documents

Text Documents

# Ingest a simple text document
doc = db.ingest_text(
    "Machine learning is fascinating and has many applications in today's world.",
    metadata={"category": "tech", "topic": "machine learning"}
)

print(f"Document ID: {doc.external_id}")

Files

# Ingest a PDF file
doc = db.ingest_file(
    "research_paper.pdf",
    metadata={"type": "research", "authors": ["John Doe", "Jane Smith"]}
)

# Ingest an image
image_doc = db.ingest_file(
    "diagram.png",
    metadata={"subject": "architecture", "project": "office building"}
)

Retrieving Documents

Retrieve Chunks

# Find relevant chunks
chunks = db.retrieve_chunks(
    "What are the applications of machine learning?",
    filters={"category": "tech"},
    k=5  # Number of results to return
)

for i, chunk in enumerate(chunks):
    print(f"Result {i+1} (Score: {chunk.score})")
    print(f"Content: {chunk.content}")
    print(f"Document ID: {chunk.document_id}")
    print("-" * 40)

Retrieve Documents

# Find relevant documents
docs = db.retrieve_docs(
    "machine learning applications",
    filters={"type": "research"},
    k=3
)

for i, doc in enumerate(docs):
    print(f"Document {i+1} (Score: {doc.score})")
    print(f"ID: {doc.document_id}")
    print(f"Metadata: {doc.metadata}")
    print("-" * 40)

Generating Completions

# Generate a completion based on document context
response = db.query(
    "Explain the main applications of machine learning in healthcare.",
    filters={"category": "tech", "topic": "machine learning"},
    temperature=0.7
)

print(response.completion)

Working with Documents

# List documents
docs = db.list_documents(limit=10, filters={"type": "research"})

# Get a specific document
doc = db.get_document(document_id="doc_12345")

Next Steps

Continue to Advanced Usage for more detailed examples.