DataBridge provides both synchronous and asynchronous clients for flexibility in different application contexts.
Synchronous Client
Initialization
from databridge import DataBridge# Create client instancedb =DataBridge( uri="databridge://dev_123:token@localhost:8000", timeout=30, # Optional request timeout in seconds is_local=True# Set True for local development (disables SSL verification))# Or use as context manager (recommended)withDataBridge(uri)as db:# Your code here
# Generate completion from contextresponse = db.query("What are the main applications of machine learning in finance?", k=3, filters={"department": "Finance"}, max_tokens=150, temperature=0.7)print("Answer:", response.completion)print(f"Total tokens used: {response.usage.total_tokens}")
retrieve_chunks()
Search for relevant document chunks using semantic similarity.
# Get first page of finance documentsdocs = db.list_documents( limit=10, filters={"department": "Finance"})# Get next pagenext_page = db.list_documents( skip=10, limit=10, filters={"department": "Finance"})
The AsyncDataBridge client provides the same functionality as the synchronous client but with async/await support.
Initialization
from databridge import AsyncDataBridgeasyncwithAsyncDataBridge( uri="databridge://dev_123:token@localhost:8000", timeout=30, is_local=True)as db:# Your async code here
Usage Example
from databridge import AsyncDataBridgeasyncdefmain():asyncwithAsyncDataBridge(uri)as db:# Ingest a document doc =await db.ingest_text( content="Example content", metadata={"category": "test"} )# Generate completion response =await db.query("What are the main points in the content?", k=3, max_tokens=150 )print("Answer:", response.completion)# Search chunks chunks =await db.retrieve_chunks("example search", k=3 )# List documents docs =await db.list_documents(limit=10)if__name__=="__main__":import asyncio asyncio.run(main())
classChunkResult: content:str score:float document_id:str# external_id chunk_number:int metadata: Dict[str, Any] content_type:str filename: Optional[str] download_url: Optional[str]defaugmented_content(self,doc: DocumentResult) ->str:"""Get augmented content for video chunks with frame/transcript info"""
DocumentResult
classDocumentResult: score:float# Highest chunk score document_id:str# external_id metadata: Dict[str, Any] content: DocumentContent # type and value fields additional_metadata: Dict[str, Any]# e.g., frame descriptions and transcripts
DocumentContent
classDocumentContent:type: Literal["url","string"]# Content type value:str# URL or actual content filename: Optional[str]# Required for URL type, None for string type