diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9a6a44a87..81d48f3c8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,5 +1,5 @@ -name: ci - +# GitHub Actions CI workflow for Go project +name: CI on: push: branches: @@ -7,40 +7,38 @@ on: pull_request: branches: - main - jobs: lint: + name: Lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.22' - # Cache is managed by golangci-lint - # https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v6.0.1 + go-version-file: go.mod + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 with: - args: --timeout=4m - version: v1.59.1 + version: v1.61 + args: --timeout=5m build-examples: + name: Build Examples runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: stable - cache: false - - uses: actions/checkout@v3 - name: Build examples run: make build-examples build-test: + name: Build and Test runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: stable - - uses: actions/checkout@v3 - name: Build run: go build -v ./... - name: Test @@ -48,3 +46,4 @@ jobs: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} GENAI_API_KEY: ${{ secrets.GENAI_API_KEY }} run: go test -v ./... + diff --git a/.golangci.yaml b/.golangci.yaml index d347aae9e..cf0d640b9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -13,7 +13,10 @@ linters: - style - test - unused + enable: + - forbidigo disable: + - gci # We don't use gci. - godox # We allow TODO lines. - tagliatelle # As we're dealing with third parties we must accept snake case. - wsl # We don't agree with wsl's style rules @@ -54,6 +57,12 @@ linters-settings: ignore-file-rules: - "**/*_test.go" - "**/mock/**/*.go" + forbidigo: + forbid: + - 'import "[^"]+/(util|common|helpers)"' + gosec: + excludes: + - G115 # https://github.com/securego/gosec/issues/1212 run: exclude-dirs: - 'exp' diff --git a/Makefile b/Makefile index 868b9f28b..84e3450eb 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ lint-all: lint-deps: @command -v golangci-lint >/dev/null 2>&1 || { \ echo >&2 "golangci-lint not found. Installing..."; \ - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1; \ + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0; \ } .PHONY: docs diff --git a/chains/sequential.go b/chains/sequential.go index 50b6d1b0a..af436f098 100644 --- a/chains/sequential.go +++ b/chains/sequential.go @@ -6,7 +6,8 @@ import ( "fmt" "strings" - "github.com/tmc/langchaingo/internal/util" + "github.com/tmc/langchaingo/internal/maputil" + "github.com/tmc/langchaingo/internal/setutil" "github.com/tmc/langchaingo/memory" "github.com/tmc/langchaingo/schema" ) @@ -42,11 +43,11 @@ func NewSequentialChain(chains []Chain, inputKeys []string, outputKeys []string, } func (c *SequentialChain) validateSeqChain() error { - knownKeys := util.ToSet(c.inputKeys) + knownKeys := setutil.ToSet(c.inputKeys) // Make sure memory keys don't collide with input keys memoryKeys := c.memory.MemoryVariables(context.Background()) - overlappingKeys := util.Intersection(memoryKeys, knownKeys) + overlappingKeys := setutil.Intersection(memoryKeys, knownKeys) if len(overlappingKeys) > 0 { return fmt.Errorf( "%w: input keys [%v] also exist in the memory keys: [%v] - please use input keys and memory keys that don't overlap", @@ -61,16 +62,16 @@ func (c *SequentialChain) validateSeqChain() error { for i, c := range c.chains { // Check that chain has input keys that are in knownKeys - missingKeys := util.Difference(c.GetInputKeys(), knownKeys) + missingKeys := setutil.Difference(c.GetInputKeys(), knownKeys) if len(missingKeys) > 0 { return fmt.Errorf( "%w: missing required input keys: [%v], only had: [%v]", - ErrChainInitialization, strings.Join(missingKeys, delimiter), strings.Join(util.ListKeys(knownKeys), delimiter), + ErrChainInitialization, strings.Join(missingKeys, delimiter), strings.Join(maputil.ListKeys(knownKeys), delimiter), ) } // Check that chain does not have output keys that are already in knownKeys - overlappingKeys := util.Intersection(c.GetOutputKeys(), knownKeys) + overlappingKeys := setutil.Intersection(c.GetOutputKeys(), knownKeys) if len(overlappingKeys) > 0 { return fmt.Errorf( "%w: chain at index %d has output keys that already exist: %v", diff --git a/documentloaders/csv.go b/documentloaders/csv.go index 2a41f4f91..9c8f73c25 100644 --- a/documentloaders/csv.go +++ b/documentloaders/csv.go @@ -51,8 +51,7 @@ func (c CSV) Load(_ context.Context) ([]schema.Document, error) { var content []string for i, value := range row { - if c.columns != nil && - len(c.columns) > 0 && + if len(c.columns) > 0 && !slices.Contains(c.columns, header[i]) { continue } diff --git a/embeddings/embedding.go b/embeddings/embedding.go index fe194ad0e..aaa478236 100644 --- a/embeddings/embedding.go +++ b/embeddings/embedding.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/tmc/langchaingo/internal/util" + "github.com/tmc/langchaingo/internal/sliceutil" ) // NewEmbedder creates a new Embedder from the given EmbedderClient, with @@ -89,7 +89,7 @@ func BatchTexts(texts []string, batchSize int) [][]string { batchedTexts := make([][]string, 0, len(texts)/batchSize+1) for i := 0; i < len(texts); i += batchSize { - batchedTexts = append(batchedTexts, texts[i:util.MinInt([]int{i + batchSize, len(texts)})]) + batchedTexts = append(batchedTexts, texts[i:sliceutil.MinInt([]int{i + batchSize, len(texts)})]) } return batchedTexts diff --git a/internal/util/download.go b/internal/imageutil/download.go similarity index 97% rename from internal/util/download.go rename to internal/imageutil/download.go index af1a93218..4ad8330c3 100644 --- a/internal/util/download.go +++ b/internal/imageutil/download.go @@ -1,4 +1,4 @@ -package util +package imageutil import ( "fmt" diff --git a/internal/maputil/map.go b/internal/maputil/map.go new file mode 100644 index 000000000..f7e64dc1d --- /dev/null +++ b/internal/maputil/map.go @@ -0,0 +1,9 @@ +package maputil + +func ListKeys[T any](m map[string]T) []string { + keys := make([]string, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + return keys +} diff --git a/internal/util/util.go b/internal/setutil/set.go similarity index 59% rename from internal/util/util.go rename to internal/setutil/set.go index 54013d2f4..a3bb0616b 100644 --- a/internal/util/util.go +++ b/internal/setutil/set.go @@ -1,5 +1,4 @@ -// Package util contains general helper functions. -package util +package setutil // ToSet converts a list to a set. func ToSet(list []string) map[string]struct{} { @@ -31,28 +30,3 @@ func Intersection(list []string, set map[string]struct{}) []string { } return intersection } - -func ListKeys[T any](m map[string]T) []string { - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - return keys -} - -// MinInt returns the minimum value in nums. -// If nums is empty, it returns 0. -func MinInt(nums []int) int { - var min int - for idx := 0; idx < len(nums); idx++ { - item := nums[idx] - if idx == 0 { - min = item - continue - } - if item < min { - min = item - } - } - return min -} diff --git a/internal/sliceutil/slice.go b/internal/sliceutil/slice.go new file mode 100644 index 000000000..0f3f4a70f --- /dev/null +++ b/internal/sliceutil/slice.go @@ -0,0 +1,18 @@ +package sliceutil + +// MinInt returns the minimum value in nums. +// If nums is empty, it returns 0. +func MinInt(nums []int) int { + var m int + for idx := 0; idx < len(nums); idx++ { + item := nums[idx] + if idx == 0 { + m = item + continue + } + if item < m { + m = item + } + } + return m +} diff --git a/internal/util/util_test.go b/internal/sliceutil/slice_test.go similarity index 96% rename from internal/util/util_test.go rename to internal/sliceutil/slice_test.go index e304cf752..15be575f8 100644 --- a/internal/util/util_test.go +++ b/internal/sliceutil/slice_test.go @@ -1,4 +1,4 @@ -package util +package sliceutil import ( "testing" diff --git a/llms/googleai/googleai.go b/llms/googleai/googleai.go index ee8e77c9b..46c357d19 100644 --- a/llms/googleai/googleai.go +++ b/llms/googleai/googleai.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/google/generative-ai-go/genai" - "github.com/tmc/langchaingo/internal/util" + "github.com/tmc/langchaingo/internal/imageutil" "github.com/tmc/langchaingo/llms" "google.golang.org/api/iterator" ) @@ -187,7 +187,7 @@ func convertParts(parts []llms.ContentPart) ([]genai.Part, error) { case llms.BinaryContent: out = genai.Blob{MIMEType: p.MIMEType, Data: p.Data} case llms.ImageURLContent: - typ, data, err := util.DownloadImageData(p.URL) + typ, data, err := imageutil.DownloadImageData(p.URL) if err != nil { return nil, err } diff --git a/llms/googleai/vertex/vertex.go b/llms/googleai/vertex/vertex.go index 03000bb2f..676efaab5 100644 --- a/llms/googleai/vertex/vertex.go +++ b/llms/googleai/vertex/vertex.go @@ -13,7 +13,7 @@ import ( "strings" "cloud.google.com/go/vertexai/genai" - "github.com/tmc/langchaingo/internal/util" + "github.com/tmc/langchaingo/internal/imageutil" "github.com/tmc/langchaingo/llms" "google.golang.org/api/iterator" ) @@ -190,7 +190,7 @@ func convertParts(parts []llms.ContentPart) ([]genai.Part, error) { case llms.BinaryContent: out = genai.Blob{MIMEType: p.MIMEType, Data: p.Data} case llms.ImageURLContent: - typ, data, err := util.DownloadImageData(p.URL) + typ, data, err := imageutil.DownloadImageData(p.URL) if err != nil { return nil, err } diff --git a/memory/sqlite3/sqlite3_history_options.go b/memory/sqlite3/sqlite3_history_options.go index 1a5eacda5..4cd6dc5ce 100644 --- a/memory/sqlite3/sqlite3_history_options.go +++ b/memory/sqlite3/sqlite3_history_options.go @@ -42,7 +42,7 @@ func WithDB(db *sql.DB) SqliteChatMessageHistoryOption { // to use a context internally when running Schema. func WithContext(ctx context.Context) SqliteChatMessageHistoryOption { return func(m *SqliteChatMessageHistory) { - m.Ctx = ctx + m.Ctx = ctx //nolint:fatcontext } } diff --git a/textsplitter/testdata/example_markdown_header_512.md b/textsplitter/testdata/example_markdown_header_512.md index caddad349..6d68b17e6 100644 --- a/textsplitter/testdata/example_markdown_header_512.md +++ b/textsplitter/testdata/example_markdown_header_512.md @@ -17,14 +17,12 @@ community looks forward to your contributions. 🎉 --- -# Contributing to langchaingo ## Table of Contents - [Code of Conduct](#code-of-conduct) - [I Have a Question](#i-have-a-question) --- -# Contributing to langchaingo ## Table of Contents - [I Want To Contribute](#i-want-to-contribute) - [Reporting Bugs](#reporting-bugs) @@ -36,7 +34,6 @@ community looks forward to your contributions. 🎉 --- -# Contributing to langchaingo ## Table of Contents - [Your First Code Contribution](#your-first-code-contribution) - [Make Changes](#make-changes) @@ -48,7 +45,6 @@ community looks forward to your contributions. 🎉 --- -# Contributing to langchaingo ## Code of Conduct This project and everyone participating in it is governed by the [langchaingo Code of Conduct](/CODE_OF_CONDUCT.md). @@ -57,14 +53,12 @@ to . --- -# Contributing to langchaingo ## I Have a Question > If you want to ask a question, we assume that you have read the > available [Documentation](https://pkg.go.dev/github.com/tmc/langchaingo). --- -# Contributing to langchaingo ## I Have a Question Before you ask a question, it is best to search for existing [Issues](https://github.com/tmc/langchaingo/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in @@ -74,7 +68,6 @@ If you then still feel the need to ask a question and need clarification, we rec --- -# Contributing to langchaingo ## I Have a Question - Provide as much context as you can about what you’re running into. - Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. @@ -82,25 +75,17 @@ We will then take care of the issue as soon as possible. --- -# Contributing to langchaingo ## I Want To Contribute -> # Contributing to langchaingo -> ## I Want To Contribute > ### Legal Notice > When contributing to this project, you must agree that you have authored 100% of the content, that you have the > necessary rights to the content and that the content you contribute may be provided under the project license. --- -# Contributing to langchaingo -## I Want To Contribute ### Reporting Bugs --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### Before Submitting a Bug Report A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the @@ -109,9 +94,6 @@ following steps in advance to help us fix any potential bug as fast as possible. --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### Before Submitting a Bug Report - Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://pkg.go.dev/github.com/tmc/langchaingo). @@ -119,9 +101,6 @@ If you are looking for support, you might want to check [this section](#i-have-a --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### Before Submitting a Bug Report - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in @@ -131,9 +110,6 @@ discussed the issue. --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### Before Submitting a Bug Report - Collect information about the bug: - Stack trace (Traceback) @@ -144,9 +120,6 @@ discussed the issue. --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### How Do I Submit a Good Bug Report? > You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue > tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to [travis.cline@gmail.com](mailto:travis.cline@gmail.com). @@ -154,9 +127,6 @@ discussed the issue. --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### How Do I Submit a Good Bug Report? We use GitHub issues to track bugs and errors. If you run into an issue with the project: - Open an [Issue](https://github.com/tmc/langchaingo/issues/new). (Since we can’t be sure at this point whether it is a @@ -165,9 +135,6 @@ bug or not, we ask you not to talk about a bug yet and not to label the issue.) --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### How Do I Submit a Good Bug Report? - Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem @@ -178,9 +145,6 @@ Once it's filed: --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### How Do I Submit a Good Bug Report? - A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs @@ -188,9 +152,6 @@ with the `needs-repro` tag will not be addressed until they are reproduced. --- -# Contributing to langchaingo -## I Want To Contribute -### Reporting Bugs #### How Do I Submit a Good Bug Report? - If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution). @@ -198,8 +159,6 @@ as `critical`), and the issue will be left to be [implemented by someone](#your- --- -# Contributing to langchaingo -## I Want To Contribute ### Suggesting Enhancements This section guides you through submitting an enhancement suggestion for langchaingo, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the @@ -207,9 +166,6 @@ community to understand your suggestion and find related suggestions. --- -# Contributing to langchaingo -## I Want To Contribute -### Suggesting Enhancements #### Before Submitting an Enhancement - Make sure that you are using the latest version. - Read the [documentation](https://pkg.go.dev/github.com/tmc/langchaingo) carefully and find out if the functionality is @@ -219,9 +175,6 @@ it has, add a comment to the existing issue instead of opening a new one. --- -# Contributing to langchaingo -## I Want To Contribute -### Suggesting Enhancements #### Before Submitting an Enhancement - Find out whether your idea fits with the scope and aims of the project. It’s up to you to make a strong case to convince the project’s developers of the merits of this feature. Keep in mind that we want features that will be @@ -230,9 +183,6 @@ consider writing an add-on/plugin library. --- -# Contributing to langchaingo -## I Want To Contribute -### Suggesting Enhancements #### How Do I Submit a Good Enhancement Suggestion? Enhancement suggestions are tracked as [GitHub issues](https://github.com/tmc/langchaingo/issues). - Use a **clear and descriptive title** for the issue to identify the suggestion. @@ -242,9 +192,6 @@ you can also tell which alternatives do not work for you. --- -# Contributing to langchaingo -## I Want To Contribute -### Suggesting Enhancements #### How Do I Submit a Good Enhancement Suggestion? - You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS @@ -254,9 +201,6 @@ Linux. --- -# Contributing to langchaingo -## I Want To Contribute -### Suggesting Enhancements #### How Do I Submit a Good Enhancement Suggestion? - **Explain why this enhancement would be useful** to most langchaingo users. You may also want to point out the other projects that solved it better and which could serve as inspiration. @@ -265,31 +209,19 @@ associated concepts in those codebases when introducing a new concept. --- -# Contributing to langchaingo -## I Want To Contribute -### Suggesting Enhancements #### How Do I Submit a Good Enhancement Suggestion? --- -# Contributing to langchaingo -## I Want To Contribute ### Your First Code Contribution --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Make Changes --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution -#### Make Changes ##### Make changes in the UI Click **Make a contribution** at the bottom of any docs page to make small changes such as a typo, sentence fix, or a broken link. This takes you to the `.md` file where you can make your changes and [create a pull request](#pull-request) @@ -297,10 +229,6 @@ for a review. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution -#### Make Changes ##### Make changes locally 1. Fork the repository. - Using GitHub Desktop: @@ -311,10 +239,6 @@ for a review. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution -#### Make Changes ##### Make changes locally - Using the command line: - [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) @@ -324,17 +248,11 @@ for a review. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Commit your update Commit the changes once you are happy with them. Don't forget to self-review to speed up the review process:zap:. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Pull Request When you're finished with the changes, create a pull request, also known as a PR. - Name your Pull Request title clearly, concisely, and prefixed with the name of primarily affected package you changed @@ -343,9 +261,6 @@ as `memory: added interfaces` or `util: added helpers`) --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Pull Request - **We strive to conceptually align with the Python and TypeScript versions of Langchain. Please link/reference the associated concepts in those codebases when introducing a new concept.** @@ -354,9 +269,6 @@ changes as well as the purpose of your pull request. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Pull Request - Don’t forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) @@ -364,9 +276,6 @@ if you are solving one. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Pull Request - Enable the checkbox to [allow maintainer edits](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork) @@ -376,9 +285,6 @@ information. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Pull Request - We may ask for changes to be made before a PR can be merged, either using [suggested changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request) @@ -387,9 +293,6 @@ your fork, then commit them to your branch. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Pull Request - As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations). @@ -398,9 +301,6 @@ help you resolve merge conflicts and other issues. --- -# Contributing to langchaingo -## I Want To Contribute -### Your First Code Contribution #### Your PR is merged! Congratulations :tada::tada: The langchaingo team thanks you :sparkles:. Once your PR is merged, your contributions will be publicly visible on the repository contributors list. diff --git a/vectorstores/chroma/chroma.go b/vectorstores/chroma/chroma.go index 82609bc07..f252ddd2c 100644 --- a/vectorstores/chroma/chroma.go +++ b/vectorstores/chroma/chroma.go @@ -139,7 +139,7 @@ func (s Store) SimilaritySearch(ctx context.Context, query string, numDocuments } filter := s.getNamespacedFilter(opts) - qr, queryErr := s.collection.Query(ctx, []string{query}, int32(numDocuments), filter, nil, s.includes) + qr, queryErr := s.collection.Query(ctx, []string{query}, safeIntToInt32(numDocuments), filter, nil, s.includes) if queryErr != nil { return nil, queryErr } @@ -212,3 +212,7 @@ func (s Store) getNamespacedFilter(opts vectorstores.Options) map[string]any { return map[string]any{"$and": []map[string]any{nameSpaceFilter, filter}} } + +func safeIntToInt32(n int) int32 { + return int32(max(0, n)) +} diff --git a/vectorstores/mongovector/mock_embedder.go b/vectorstores/mongovector/mock_embedder.go index a1e40ffb6..bed85b7df 100644 --- a/vectorstores/mongovector/mock_embedder.go +++ b/vectorstores/mongovector/mock_embedder.go @@ -105,17 +105,13 @@ func flushMockDocuments(ctx context.Context, store Store, emb *mockEmbedder) err return nil } -// newNormalizedFloat32 will generate a random float32 in [-1, 1]. -// nolint:mnd func newNormalizedFloat32() (float32, error) { - max := big.NewInt(1 << 24) - - n, err := rand.Int(rand.Reader, max) + maxInt := big.NewInt(1 << 24) + n, err := rand.Int(rand.Reader, maxInt) if err != nil { return 0.0, fmt.Errorf("failed to normalize float32") } - - return 2.0*(float32(n.Int64())/float32(1<<24)) - 1.0, nil + return 2.0*(float32(n.Int64())/float32(maxInt.Int64())) - 1.0, nil } // dotProduct will return the dot product between two slices of f32.