Skip to main content

Python client library for Memory Service gRPC API

Project description

Memory Service Client

A Python client library for the Memory Service gRPC API.

Installation

pip install memory-service-client

Usage

Basic Usage

from memory_service_client import MemoryServiceClient

# Connect to the service
with MemoryServiceClient("localhost:50051") as client:
    # Process a document
    response = client.process_document(
        document_id="doc1",
        content="This is a sample document content.",
        title="Sample Document"
    )
    print(f"Document processed: {response.status}")
    
    # Query knowledge
    response = client.query_knowledge(
        query="What is this document about?",
        top_k=3
    )
    print(f"Answer: {response.answer}")

Using gRPC Stubs Directly

import grpc
from memory_service_client import RagServiceStub, ProcessDocumentRequest, ChunkingConfig

# Create channel and stub
channel = grpc.insecure_channel("localhost:50051")
stub = RagServiceStub(channel)

# Create request
request = ProcessDocumentRequest(
    document_id="doc1",
    content="Document content",
    chunking_config=ChunkingConfig(
        chunk_size=1000,
        chunk_overlap=100,
        strategy="sentence"
    )
)

# Make the call
response = stub.ProcessDocument(request)
print(response)

API Reference

MemoryServiceClient

High-level client class that provides convenient methods for interacting with the Memory Service.

Methods

  • process_document(document_id, content, title="", source_url="", metadata=None, chunk_size=1000, chunk_overlap=100, chunking_strategy="sentence"): Process a document for RAG
  • query_knowledge(query, top_k=5, similarity_threshold=0.7, include_metadata=True, use_reranking=False, llm_model="gpt-3.5-turbo", max_tokens=1000): Query the knowledge base
  • get_document_status(document_id): Get document processing status
  • hello_world(name="World"): Test connection

gRPC Messages

The library exposes all protobuf message types:

  • ProcessDocumentRequest, ProcessDocumentResponse
  • QueryKnowledgeRequest, QueryKnowledgeResponse
  • DocumentStatusRequest, DocumentStatusResponse
  • HelloWorldRequest, HelloWorldResponse
  • ChunkingConfig, QueryConfig
  • ProcessingStats, QueryStats, RetrievedChunk

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black .

# Lint code
ruff check .

License

MIT License

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

memory_service_client-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

memory_service_client-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: memory_service_client-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for memory_service_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 77916839d3759977feabde3ca29cdc92757a42699d7cedbbeea8b9aa5d32f3e1
MD5 48054ef200b439e7f2dd8eb56dfe6c98
BLAKE2b-256 76b4dad6bffbb567f82e29b4ff63eadc65a9784bc3b0b3c4c8f3a90b03b80fa6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for memory_service_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b09bfac70d27b3eb43f6f88900cae356cc7a85e4c7bee5a49a2d9f4d2cd081e3
MD5 348d009e219f5ba5fd0fb6c692c66a80
BLAKE2b-256 47e37521a807fdb924f9fdd124d5876c1d1c2a2057d2209e32dd82e6240ce842

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