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.3.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.3.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: memory_service_client-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 f4582a39f033deb252ef8bcd7e93a6bd7acf9dc6b7508875851c0c5ce7322ec8
MD5 40784450808d72fd41ba1cdcab389a50
BLAKE2b-256 58abcf9b6b8488269b4a686bf10d5c125c7df4a897e0ca05b64c1399d0814fd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for memory_service_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0f385605348ef4ffb13bffc5a42315f447bf781b29e960d25452ce4e61f7573
MD5 3e41c6b6bc50e43a9d10235e616323a9
BLAKE2b-256 2973b76512ec4c1d7228826ab16b1ed3fc328a9b9b3356a506a682458607b0b8

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