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.
Create Namespace Examples
# Create a text namespace for Moorcheh to handle embeddings
client.namespaces.create(
    namespace_name="my-faq-documents",
    type="text"
)

# Create a vector namespace for your own embeddings
client.namespaces.create(
    namespace_name="my-image-embeddings",
    type="vector",
    vector_dimension=768
)

namespaces.list

Retrieves a list of all namespaces accessible by your API key. Returns: Dict[str, Any] - A dictionary containing a list of namespace objects under the namespaces key.
List Namespaces Example
all_namespaces = client.namespaces.list()
for ns in all_namespaces.get('namespaces', []):
    print(f"- Namespace: {ns['namespace_name']}, Type: {ns['type']}, Items: {ns['itemCount']}")

namespaces.delete

Permanently deletes a namespace and all its contents. This action is irreversible.

Parameters

namespace_name
str
required
The exact name of the namespace to delete.
Returns: None. Raises: NamespaceNotFound.
Delete Namespace Example
client.namespaces.delete(namespace_name="my-temporary-namespace")
Deleting a namespace permanently removes all data within it. This action cannot be undone.

Complete Example

Complete Namespace Management Example
from moorcheh_sdk import MoorchehClient, ConflictError, NamespaceNotFound

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

    # List all namespaces
    namespaces = client.namespaces.list()
    print(f"Found {len(namespaces['namespaces'])} namespaces")

    # Delete namespace when done
    try:
        client.namespaces.delete("my-temporary-namespace")
        print("Namespace deleted successfully")
    except NamespaceNotFound:
        print("Namespace was not found")

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