Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions clients/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Microsoft Kernel Memory Python Libraries 🐍

This directory contains three Python packages that provide different ways to interact with Microsoft Kernel Memory:

## πŸ“¦ kernel-memory-client

An autogenerated Python client library for interacting with the Kernel Memory API. This client provides low-level access to all Kernel Memory endpoints and operations.

```python
from kernel_memory_client import Client

# Create a client
client = Client(base_url="http://localhost:9001")

# Use the client to interact with Kernel Memory
# ...
```

**Generation Info:** The client was autogenerated using the OpenAPI specification (`swagger.json`) and the `openapi-python-client` tool:

```shell
cd clients/python/kernel-memory-cli
openapi-python-client generate --path ../../swagger.json --config openapi-python-generator-config.yml --overwrrite
```

**Note:** The following patch was applied to fix the document upload functionality:

```patch
# clients/python/kernel-memory-client/kernel_memory_client/models/upload_document_body.py
@@ -1,11 +1,3 @@
files: Union[Unset, tuple[None, bytes, str]] = UNSET
if not isinstance(self.files, Unset):
- _temp_files = []
- for files_item_data in self.files:
- files_item = files_item_data.to_tuple()
-
- _temp_files.append(files_item)
- files = (None, json.dumps(_temp_files).encode(), "application/json")
-
+ files = files
```

## πŸ–₯️ kernel-memory-cli

A command-line interface for Microsoft Kernel Memory that provides an easy way to interact with Kernel Memory services from the terminal.

```bash
# Install the CLI
pip install kernel-memory-cli

# Configure the CLI
kernel-memory config --base-url http://localhost:9001

# Upload a document
kernel-memory upload mydocument.pdf

# Search for information
kernel-memory search "my query"

# Ask questions about your documents
kernel-memory ask "What does my document say about machine learning?"
```

The CLI offers intuitive commands for configuring connections, uploading documents, searching content, and asking questions about your indexed documents.

## πŸ”Œ semantic-kernel-memory-plugin

A plugin that integrates Kernel Memory with Semantic Kernel, allowing you to use Kernel Memory's document processing and retrieval capabilities within your Semantic Kernel applications.

```python
from semantic_kernel import Kernel
from semantic_kernel_memory_plugin.memory_plugin import MemoryPlugin
from kernel_memory_client import Client, AuthenticatedClient

# Create a Semantic Kernel instance
kernel = Kernel()

# Add the Kernel Memory plugin

memory_client = AuthenticatedClient(
base_url="http://localhost:9001")

memory_plugin = MemoryPlugin(memory_client=memory_client)
kernel.add_plugin(memory_plugin)

# Now use Kernel Memory capabilities in your Semantic Kernel app
# ...
```

This plugin bridges the powerful memory capabilities of Kernel Memory with the flexible AI orchestration of Semantic Kernel.
128 changes: 128 additions & 0 deletions clients/python/kernel-memory-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Kernel Memory CLI

A command line interface for Microsoft Kernel Memory based on python.

## Installation

```bash
pip install kernel-memory-cli
```

## Getting Started

Before using Kernel Memory CLI, you need to configure it:

```bash
kernel-memory config --base-url http://localhost:9001
```

If you need authentication:

```bash
kernel-memory config --base-url http://your-api-url --token your-api-token
```

## Commands

### Configuration

- Set up the CLI:
```bash
kernel-memory config --base-url <url> [--token <token>] [--default-index <index>]
```

- View current configuration:
```bash
kernel-memory show
```

### Working with Documents

- Upload a document:
```bash
kernel-memory upload <file_path> [--index <index>] [--document-id <id>] [--tags <tag1:value1>]
```

- Search document snippets:
```bash
kernel-memory search "your search query" [--index <index>] [--limit 3] [--filter-tags <tag1:value1>]
```

- Ask questions:
```bash
kernel-memory ask "your question" [--index <index>] [--filter-tags <tag1:value1>]
```

- List available indices:
```bash
kernel-memory list
```

![Help](./docs/help.png)
![List](./docs/list.png)

## Advanced Usage Examples

### Custom Processing Pipeline

You can customize the document processing pipeline using the `--steps` option when uploading:

```bash
kernel-memory upload --steps extract --steps partition --steps gen_embeddings --steps save_records mydocs-NASA-news.pdf
```

This command uploads a PDF document about NASA news and processes it through these specific pipeline steps:
1. `extract` - Extracts text content from the PDF
2. `partition` - Divides the content into manageable chunks
3. `gen_embeddings` - Generates vector embeddings for each chunk
4. `save_records` - Saves the processed chunks in the index

![Upload](./docs/upload.png)

### Searching for Information

To search for specific information in your documents:

```bash
kernel-memory search "Tell me the latest news about Artemis (a Nasa project)"
```

This command performs a semantic search in your index and returns the most relevant document snippets related to the Artemis project. Each result shows:
- Document ID
- Relevant content snippet
- Relevance score
- Associated tags (if available)

![Search](./docs/search.png)

### Asking Questions

For more advanced question answering:

```bash
kernel-memory ask "Tell me the latest news about Artemis (a Nasa project)"
```

Unlike the search command that returns raw snippets, the `ask` command:
1. Retrieves the most relevant information about the Artemis project
2. Generates a comprehensive answer synthesizing the information
3. Provides citations to the source documents
4. Creates a cohesive response that directly answers your question

![Ask](./docs/ask.png)

## Environment Variables

You can configure the CLI using environment variables:

- `KM_BASE_URL` - Base URL for the API
- `KM_TOKEN` - Authentication token
- `KM_TOKEN_PREFIX` - Prefix for the token
- `KM_DEFAULT_INDEX` - Default index to use
- `KM_TIMEOUT` - Request timeout in seconds
- `KM_VERIFY_SSL` - Whether to verify SSL certificates
- `KM_CONFIG_PATH` - Path to config file

## License

[MIT License](LICENSE)
Binary file added clients/python/kernel-memory-cli/docs/ask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/python/kernel-memory-cli/docs/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clients/python/kernel-memory-cli/docs/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading