Skip to main content

namespaces.create

Creates a new namespace for storing data.

Parameters

namespace_name
str
required
A unique name for the namespace.
type
str
required
The type of namespace: “text” or “vector”.
vector_dimension
Optional[int]
The dimension of vectors. Required only if type is “vector”.
Returns: Dict[str, Any] - A dictionary confirming the creation details. Raises: ConflictError, InvalidInputError.

Examples

Create Text Namespace
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    # Create a text namespace for Moorcheh to handle embeddings
    result = client.namespaces.create(
        namespace_name="my-faq-documents",
        type="text"
    )
    print(f"Created namespace: {result}")
Create Vector Namespace
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    # Create a vector namespace for your own embeddings
    result = client.namespaces.create(
        namespace_name="my-image-embeddings",
        type="vector",
        vector_dimension=768
    )
    print(f"Created namespace: {result}")

Error Handling

Error Handling Example
from moorcheh_sdk import MoorchehClient, ConflictError, InvalidInputError

with MoorchehClient() as client:
    try:
        result = client.namespaces.create(
            namespace_name="my-documents",
            type="text"
        )
        print(f"Created namespace: {result}")
    except ConflictError:
        print("Namespace already exists")
    except InvalidInputError as e:
        print(f"Invalid input: {e}")

Namespace Types

FeatureText NamespacesVector Namespaces
Primary UseStoring and searching text documentsStoring pre-computed vector embeddings
EmbeddingsAutomatically generated by MoorchehProvided by you (custom embeddings)
RequirementsNoneMust specify vector dimension
Search CapabilitiesFull-text searchVector similarity search
Ideal ForFAQs, documentation, articlesImage embeddings, custom ML models

Best Practices

  • Use descriptive namespace names that indicate their purpose
  • Separate different types of content into different namespaces
  • Consider your data organization strategy before creating namespaces
  • Text namespaces are easier to work with for most use cases
  • Only use vector namespaces if you need to provide your own embeddings