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

Uploaded Python 3

File details

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

File metadata

  • Download URL: memory_service_client-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 b1eab8a52fa5b7a0cd3801122ec671949fea756766b0b728e6508798db9c1cfa
MD5 f5183bba870e5d1d3ae80c1ce22eca4c
BLAKE2b-256 6c49f9984fb2cda5c432b1b947f4755fe9803c0aab3045d159d55f8b344a9d45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for memory_service_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1df018ea60a2fb53af6148bcef2c7eb678b6d114e1279ec51674efc7bfe4dc84
MD5 0be2616f63cd2c4978a54288566f6bab
BLAKE2b-256 6868f75a399dbbbba1fcdf87c31d22b4e2298f2dd158635fee6e0fd32fbfcf12

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