Skip to main content

Python client for the Cognitor search platform API.

Project description

Cognitor | All-in-one semantic search engine for AI and humans.

cognitor-python

Python SDK for Cognitor.

Installation

pip install cognitor

Quick start

from cognitor import Cognitor

with Cognitor("http://localhost:7530", api_key="your-api-key") as client:
    print(client.ping())
    print(client.health_ready())  # "ready" or "loading"

The api_key parameter is optional, omit it if your cognitor instance does not require authentication.

Usage

Collections

# Create a collection (server-side embedding)
collection = client.create_collection(
    "my-collection",
    emb_model="text-embedding-3-small",
)

# Create a collection with a fixed vector dimension (client-side embedding)
collection = client.create_collection("my-collection", dim=1536)

# List all collections
collections = client.list_collections()

# Get a single collection
collection = client.get_collection("my-collection")

# Delete a collection
client.delete_collection("my-collection")

Documents

# Add documents (texts are embedded server-side when emb_model is set)
ids = client.add_documents(
    "my-collection",
    texts=["Hello world", "Cognitor is a vector store"],
    metadatas=[{"source": "docs"}, {"source": "docs"}],
)

# Add documents with explicit vectors (client-side embedding)
ids = client.add_documents(
    "my-collection",
    texts=["Hello world"],
    metadatas=[{"source": "docs"}],
    vectors=[[0.1, 0.2, ...]],
)

# Add a large number of documents in batches
ids = client.bulk_add_documents(
    "my-collection",
    texts=[...],
    metadatas=[...],
    batch_size=512,
)

# List documents (paginated)
page = client.list_documents("my-collection", offset=0, limit=50)
print(page.total, page.documents)

# Get a single document
doc = client.get_document("my-collection", doc_id)

# Update document metadata
doc = client.update_document_metadata("my-collection", doc_id, {"source": "updated"})

# Delete a document
client.delete_document("my-collection", doc_id)

Search

# Search by text (requires server-side embedding model)
response = client.search("my-collection", query_text="Hello", top_k=10)

# Search by vector
response = client.search("my-collection", query_vector=[0.1, 0.2, ...], top_k=10)

# Filter results by metadata
response = client.search(
    "my-collection",
    query_text="Hello",
    filters={"source": "docs"},
)

# Include vectors in results
response = client.search("my-collection", query_text="Hello", include_vectors=True)

for hit in response.results:
    print(f"score={hit.score:.4f}  text={hit.text!r}")

Admin

# Compact a collection (removes deleted vectors)
result = client.compact("my-collection")
print(result.deleted_count, "vectors removed")

Health

# Readiness probe status
status = client.health_ready()
if status == "ready":
    print("Server is ready")
else:
    print("Server is still loading models")

Connection management

Use the client as a context manager (recommended) to ensure the underlying HTTP connection is closed:

with Cognitor("http://localhost:7530") as client:
    ...

Or close it manually:

client = Cognitor("http://localhost:7530")
try:
    ...
finally:
    client.close()

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

cognitor-0.4.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

cognitor-0.4.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file cognitor-0.4.0.tar.gz.

File metadata

  • Download URL: cognitor-0.4.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for cognitor-0.4.0.tar.gz
Algorithm Hash digest
SHA256 37894690c09bf615b32768922f13df5f1322275fda0b7b8f7cc751742109377c
MD5 ad9b3dd29772ec79008c2d8b5db55f65
BLAKE2b-256 2f709b8b8b4c6304c6670bfa397fbc96521af31c7649100fb555714c70365ec8

See more details on using hashes here.

File details

Details for the file cognitor-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: cognitor-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for cognitor-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf1b670cdf6384a9866232964b77d367f9119ee605e0a7baa4ec518543756821
MD5 c7c8a330ae3ac8d752717f2547d9d2cb
BLAKE2b-256 b2b358e894eb86a832a4102928ec21c0f9e7cce030fa370781d64af88acabfda

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