kno-sdk
A Python library for cloning, indexing, and semantically searching Git repositories using embeddings (OpenAI or SBERT) and Chroma — plus a high-level agent_query for autonomous code agent.
🚀 Features
- Clone or update any Git repository with a single call
- Extract semantic code chunks via Tree-Sitter grammars (functions, classes, methods, etc.)
- Fallback to line-based chunking for unsupported languages or large files
- Embed code or text with your choice of:
- OpenAI's
text-embedding-ada-002via OpenAIEmbeddings - Local SBERT model (e.g.
microsoft/graphcodebert-base) via SBERTEmbeddings
- OpenAI's
- Persist vector store in a
.kno/folder using Chroma - Auto-commit & push the embedding database back to your repo
- Fast similarity search over indexed code chunks
- Autonomous agent for code analysis via
agent_query()
📦 Installation
pip install kno-sdk
🏁 Quickstart
from kno_sdk import clone_and_index, search, EmbeddingMethod
# 1. Clone (or pull) and index a repository
repo_index = clone_and_index(
repo_url="https://github.com/SyedGhazanferAnwar/NestJs-MovieApp",
branch="master",
embedding=EmbeddingMethod.SBERT, # or EmbeddingMethod.OPENAI
cloned_repo_base_dir="repos" # where to clone locally
)
print("Indexed at:", repo_index.path)
print("Directory snapshot:\n", repo_index.digest)
# 2. Perform semantic search
results = search(
repo_url="https://github.com/SyedGhazanferAnwar/NestJs-MovieApp",
branch="master",
embedding=EmbeddingMethod.SBERT,
cloned_repo_base_dir="repos",
query="NestFactory",
k=5
)
for i, chunk in enumerate(results, 1):
print(f"--- Result #{i} ---\n{chunk}\n")
# 3. Autonomous Code-Analysis Agent
from kno_sdk import agent_query, EmbeddingMethod, LLMProvider
# First create a repo index
repo_index = clone_and_index(
repo_url="https://github.com/WebGoat/WebGoat",
branch="main",
embedding=EmbeddingMethod.SBERT,
cloned_repo_base_dir="repos"
)
# Then use the index with agent_query
result = agent_query(
repo_index=repo_index,
llm_provider=LLMProvider.ANTHROPIC,
llm_model="claude-3-haiku-20240307",
llm_temperature=0.0,
llm_max_tokens=4096,
llm_system_prompt="You are a senior code-analysis agent.",
prompt="Find issues, bugs and vulnerabilities in this repo, and explain each with exact code locations.",
MODEL_API_KEY="your_api_key_here"
)
print(result)
📖 API Reference
clone_and_index(...) → RepoIndex
Clone (or pull) a repository, embed its files, and persist a Chroma database in .kno folder. Finally, commit & push the .kno/ folder back to the original repo.
def clone_and_index(
repo_url: str,
branch: str = "main",
embedding: EmbeddingMethod = EmbeddingMethod.SBERT,
cloned_repo_base_dir: str = "."
) -> RepoIndex
-
repo_url — Git HTTPS/SSH URL
-
branch — branch to clone or update (default: main)
-
embedding — EmbeddingMethod.OPENAI or EmbeddingMethod.SBERT
-
base_dir — local directory to clone into (default: current working dir)
Returns a RepoIndex object with:
-
path: pathlib.Path — local clone directory
-
digest: str — textual snapshot of the directory tree
-
vector_store: Chroma — the Chroma collection instance
search(...) → List[str]
Run a similarity search on an existing .kno/ Chroma database.
def search(
repo_url: str,
branch: str = "main",
embedding: EmbeddingMethod = EmbeddingMethod.SBERT,
query: str = "",
k: int = 8,
cloned_repo_base_dir: str = "."
) -> List[str]
-
query — your natural-language or code search prompt
-
k — number of top results to return
Returns a list of the top-k matching code/text chunks.
agent_query(...) → str
High-level agent that clones, indexes, and then iteratively uses tools (search_code, read_file, etc.) plus an LLM to fulfill your prompt.
def agent_query(
repo_url: str,
branch: str = "main",
embedding: EmbeddingMethod = EmbeddingMethod.SBERT,
cloned_repo_base_dir: str = str(Path.cwd()),
llm_provider: LLMProvider = LLMProvider.ANTHROPIC,
llm_model: str = "claude-3-haiku-20240307",
llm_temperature: float = 0.0,
llm_max_tokens: int = 4096,
llm_system_prompt: str = "",
prompt: str = "",
MODEL_API_KEY: str = "",
) -> str
-
repo_url, branch, embedding, base_dir — same as above
-
llm_provider — LLMProvider.OPENAI or LLMProvider.ANTHROPIC
-
llm_model — model name (e.g. "gpt-4" or "claude-3-haiku-20240307")
-
llm_temperature, llm_max_tokens — sampling params
-
llm_system_prompt — initial system message for the agent
-
prompt — your user query/task description
-
MODEL_API_KEY — sets OPENAI_API_KEY or ANTHROPIC_API_KEY
Returns the agent's Final Answer as a string.
EmbeddingMethod
class EmbeddingMethod(str, Enum):
OPENAI = "OpenAIEmbeddings"
SBERT = "SBERTEmbeddings"
Choose between OpenAI's hosted embeddings or a local SBERT model.
🔍 How It Works
-
Clone or PullUses GitPython to clone depth-1 or pull the latest changes.
-
Directory SnapshotBuilds a small "digest" of files/folders (up to ~1 K tokens).
-
Chunk Extraction
-
Tree-sitter for language-aware extraction of functions, classes, etc.
-
Fallback to fixed-size line chunks for unknown languages or large files.
-
-
Embedding
-
Streams each chunk into your chosen embedding backend.
-
Respects a 16 000-token cap per chunk.
-
-
Vector Store
-
Persists embeddings in a namespaced Chroma collection under .kno/.
-
Only indexes files once (skips already-populated collections).
-
-
Commit & Push
- Automatically stages, commits, and pushes .kno/ back to your remote.
-
Autonomous Agent
-
RAG prompt
-
Tool calls (search_code, read_file, …)
-
Iterative LLM planning & execution
-
Stops on "Final Answer:" or max iterations
⚙️ Configuration
-
Skip directories: .git, node_modules, build, dist, target, .vscode, .kno
-
Skip files: package-lock.json, yarn.lock, .prettierignore
-
Binary extensions: common image, audio, video, archive, font, and binary file types
All of the above can be modified by forking the source and adjusting the skip_dirs, skip_files, and BINARY_EXTS sets.
🔧 Dependencies
🤝 Contributing
-
Fork this repo
-
Create your feature branch (git checkout -b feature/AmazingFeature)
-
Commit your changes (git commit -m 'Add amazing feature')
-
Push to the branch (git push origin feature/AmazingFeature)
-
Open a Pull Request
Please run pytest before submitting and follow the existing code style.
Metadata
Release files for kno-sdk 1.4.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kno_sdk-1.4.10.tar.gz | 18.5 kB | Without provenance | Details for kno_sdk-1.4.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kno_sdk-1.4.10-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for kno_sdk-1.4.10-py2.py3-none-any.whl |
Total release size: 34.4 kB
Release files / kno_sdk-1.4.10.tar.gz
| Download URL | kno_sdk-1.4.10.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42ce1a8fb8e0bb3e022ef92176611063e0540931412c7aa57a2b2a5b736c6754
|
|
BLAKE2b-256 checksum How to use checksums |
7124988b97adccb4eac1615bd57ba533bd0f910d62cfdee5bd178e388f20de9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / kno_sdk-1.4.10-py2.py3-none-any.whl
| Download URL | kno_sdk-1.4.10-py2.py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
dbc77fcaa84aafcb5234fa9deceb6b7b0e90ec81a0c20d3a0d662da34cc277c6
|
|
BLAKE2b-256 checksum How to use checksums |
4b48c491f41435ef901143536b0eed52364567563ba1e535bbab1c02d39dd802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for kno-sdk 1.4.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.